/
06-payment-create-card-token.php
83 lines (68 loc) · 2.36 KB
/
06-payment-create-card-token.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once __DIR__ . '/..' . '/config.php';
$paymentTransaction = new \Ipag\Sdk\Model\PaymentTransaction(
[
'amount' => 100,
'callback_url' => 'https://ipag-sdk.requestcatcher.com/callback',
'payment' => [
'type' => Ipag\Sdk\Core\Enums\PaymentTypes::CARD,
'installments' => 2,
'card' => [
'token' => '552af952-e189-45d5-b974-e5bb87385e01'
]
],
'customer' => [
'name' => 'Bruce Wayne',
'cpf_cnpj' => '490.558.550-30',
]
]
);
try {
$responsePayment = $ipagClient->payment()->create($paymentTransaction);
$data = $responsePayment->getData();
$statusPayment = $responsePayment->getParsedPath('attributes.status.code');
$statusGateway = $responsePayment->getParsedPath('attributes.gateway.code');
$statusAcquirer = $responsePayment->getParsedPath('attributes.acquirer.code');
// Verifica o status retornado do pagamento
switch ($statusPayment) {
case Ipag\Sdk\Core\Enums\PaymentStatus::CAPTURED:
case Ipag\Sdk\Core\Enums\PaymentStatus::PRE_AUTHORIZED:
// Faça algo aqui...
break;
default:
// Faça algo aqui...
}
// Verifica o status retornado do gateway de pagamento
switch ($statusGateway) {
case Ipag\Sdk\Core\Enums\GatewayStatus::SUCCEED:
// Faça algo aqui...
break;
default:
// Faça algo aqui...
}
// Verifica o status retornado da Adquirente de pagamento
switch ($statusAcquirer) {
case Ipag\Sdk\Core\Enums\AcquirerStatus::APPROVED_OR_COMPLETED_SUCCESSFULLY:
// Faça algo aqui...
break;
default:
// Faça algo aqui...
}
echo "Status do Pagamento retornado: {$statusPayment}" . PHP_EOL;
echo "Status da Gateway: {$statusGateway}" . PHP_EOL;
echo "Status da Adquirente: {$statusAcquirer}" . PHP_EOL;
echo "<pre>" . PHP_EOL;
print_r($data);
echo "</pre>" . PHP_EOL;
} catch (Ipag\Sdk\Exception\HttpException $e) {
$code = $e->getResponse()->getStatusCode();
$errors = $e->getErrors();
echo "<pre>" . PHP_EOL;
var_dump($code, $errors);
echo "</pre>" . PHP_EOL;
} catch (Exception $e) {
$error = $e->getMessage();
echo "<pre>" . PHP_EOL;
var_dump($error);
echo "</pre>" . PHP_EOL;
}