|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Tip: This setup section generally goes in other files, |
|
5
|
|
|
* and you access them in your controllers as globals, |
|
6
|
|
|
* instead of reinstantiating them every time. |
|
7
|
|
|
*/ |
|
8
|
|
|
require 'vendor/autoload.php'; |
|
9
|
|
|
|
|
10
|
|
|
use Moip\Auth\BasicAuth; |
|
11
|
|
|
use Moip\Moip; |
|
12
|
|
|
|
|
13
|
|
|
$token = 'YOUR-TOKEN'; |
|
14
|
|
|
$key = 'YOUR-KEY'; |
|
15
|
|
|
$moip = new Moip(new BasicAuth($token, $key), Moip::ENDPOINT_SANDBOX); |
|
16
|
|
|
|
|
17
|
|
|
/* |
|
18
|
|
|
* Don't forget you must generate your hash to encrypt credit card data using https://github.com/moip/moip-sdk-js |
|
19
|
|
|
*/ |
|
20
|
|
|
$hash = 'YOUR-HASH'; |
|
21
|
|
|
|
|
22
|
|
|
try { |
|
23
|
|
|
/* |
|
24
|
|
|
* If you want to persist your customer data and save later, now is the time to create it. |
|
25
|
|
|
* TIP: Don't forget to generate your `ownId` or use one you already have, |
|
26
|
|
|
* here we set using uniqid() function. |
|
27
|
|
|
*/ |
|
28
|
|
|
$customer = $moip->customers()->setOwnId(uniqid()) |
|
29
|
|
|
->setFullname('Fulano de Tal') |
|
30
|
|
|
->setEmail('[email protected]') |
|
31
|
|
|
->setBirthDate('1988-12-30') |
|
32
|
|
|
->setTaxDocument('22222222222') |
|
33
|
|
|
->setPhone(11, 66778899) |
|
34
|
|
|
->addAddress('BILLING', |
|
35
|
|
|
'Rua de teste', 123, |
|
36
|
|
|
'Bairro', 'Sao Paulo', 'SP', |
|
37
|
|
|
'01234567', 8) |
|
38
|
|
|
->addAddress('SHIPPING', |
|
39
|
|
|
'Rua de teste do SHIPPING', 123, |
|
40
|
|
|
'Bairro do SHIPPING', 'Sao Paulo', 'SP', |
|
41
|
|
|
'01234567', 8) |
|
42
|
|
|
->create(); |
|
43
|
|
|
|
|
44
|
|
|
// Creating an order |
|
45
|
|
|
$order = $moip->orders()->setOwnId(uniqid()) |
|
46
|
|
|
->addItem('bicicleta 1', 1, 'sku1', 10000) |
|
47
|
|
|
->addItem('bicicleta 2', 1, 'sku2', 11000) |
|
48
|
|
|
->addItem('bicicleta 3', 1, 'sku3', 12000) |
|
49
|
|
|
->addItem('bicicleta 4', 1, 'sku4', 13000) |
|
50
|
|
|
->addItem('bicicleta 5', 1, 'sku5', 14000) |
|
51
|
|
|
->addItem('bicicleta 6', 1, 'sku6', 15000) |
|
52
|
|
|
->addItem('bicicleta 7', 1, 'sku7', 16000) |
|
53
|
|
|
->addItem('bicicleta 8', 1, 'sku8', 17000) |
|
54
|
|
|
->addItem('bicicleta 9', 1, 'sku9', 18000) |
|
55
|
|
|
->addItem('bicicleta 10', 1, 'sku10', 19000) |
|
56
|
|
|
->setShippingAmount(3000)->setAddition(1000)->setDiscount(5000) |
|
57
|
|
|
->setCustomer($customer) |
|
|
|
|
|
|
58
|
|
|
->create(); |
|
59
|
|
|
|
|
60
|
|
|
// Creating payment to order |
|
61
|
|
|
$payment = $order->payments() |
|
|
|
|
|
|
62
|
|
|
->setCreditCardHash($hash, $customer) |
|
63
|
|
|
->setInstallmentCount(3) |
|
64
|
|
|
->setStatementDescriptor('teste de pag') |
|
65
|
|
|
->execute(); |
|
66
|
|
|
|
|
67
|
|
|
echo 'Order ID: '.$order->getId().'<br />'; |
|
|
|
|
|
|
68
|
|
|
echo 'Payment ID: '.$payment->getId().'<br />'; |
|
69
|
|
|
echo 'Created at: '.$payment->getCreatedAt()->format('Y-m-d H:i:s').'<br />'; |
|
70
|
|
|
echo 'Status: '.$payment->getStatus().'<br />'; |
|
71
|
|
|
echo 'Amount: '.$payment->getAmount()->total.'<br />'; |
|
72
|
|
|
echo 'Funding Instrument: '.$payment->getFundingInstrument()->method.'<br />'; |
|
73
|
|
|
echo 'Installment Count: '.$payment->getInstallmentCount().'<br />'; |
|
74
|
|
|
} catch (\Moip\Exceptions\UnautorizedException $e) { |
|
75
|
|
|
echo $e->getMessage(); |
|
76
|
|
|
} catch (\Moip\Exceptions\ValidationException $e) { |
|
77
|
|
|
printf($e->__toString()); |
|
78
|
|
|
} catch (\Moip\Exceptions\UnexpectedException $e) { |
|
79
|
|
|
echo $e->getMessage(); |
|
80
|
|
|
} |
|
81
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: