1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ipag\Classes\Services; |
4
|
|
|
|
5
|
|
|
use Ipag\Classes\Contracts\Populable; |
6
|
|
|
use Ipag\Classes\Util\ObjectUtil; |
7
|
|
|
use stdClass; |
8
|
|
|
|
9
|
|
|
final class TransactionResponseService implements Populable |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var ObjectUtil |
13
|
|
|
*/ |
14
|
|
|
private $objectUtil; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param stdClass $response |
18
|
|
|
* |
19
|
|
|
* @return stdClass |
20
|
|
|
*/ |
21
|
|
|
public function populate(stdClass $response) |
22
|
|
|
{ |
23
|
|
|
$transaction = $this->transaction($response); |
24
|
|
|
|
25
|
|
|
$transaction->creditCard = $this->creditCard($response); |
26
|
|
|
|
27
|
|
|
if (isset($response->id_assinatura)) { |
28
|
|
|
$transaction->subscription = $this->subscription($response); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return $transaction; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
private function getObjectUtil() |
35
|
|
|
{ |
36
|
|
|
if (is_null($this->objectUtil)) { |
37
|
|
|
$this->objectUtil = new ObjectUtil(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->objectUtil; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function transaction(stdClass $response) |
44
|
|
|
{ |
45
|
|
|
$transaction = new stdClass(); |
46
|
|
|
$transaction->tid = $this->getObjectUtil()->getProperty($response, 'id_transacao'); |
47
|
|
|
$transaction->authId = $this->getObjectUtil()->getProperty($response, 'autorizacao_id'); |
48
|
|
|
$transaction->amount = $this->getObjectUtil()->getProperty($response, 'valor'); |
49
|
|
|
$transaction->acquirer = $this->getObjectUtil()->getProperty($response, 'operadora'); |
50
|
|
|
$transaction->acquirerMessage = $this->getObjectUtil()->getProperty($response, 'operadora_mensagem'); |
51
|
|
|
$transaction->urlAuthentication = $this->getObjectUtil()->getProperty($response, 'url_autenticacao'); |
52
|
|
|
$transaction->payment = $this->payment($response); |
53
|
|
|
$transaction->order = $this->order($response); |
54
|
|
|
$transaction->antifraud = $this->antifraud($response); |
55
|
|
|
$transaction->splitRules = $this->splitRules($response); |
56
|
|
|
|
57
|
|
|
$transaction->error = $this->getObjectUtil()->getProperty($response, 'code'); |
58
|
|
|
$transaction->errorMessage = $this->getObjectUtil()->getProperty($response, 'message'); |
59
|
|
|
|
60
|
|
|
return $transaction; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function payment(stdClass $response) |
64
|
|
|
{ |
65
|
|
|
$payment = new stdClass(); |
66
|
|
|
$payment->status = $this->getObjectUtil()->getProperty($response, 'status_pagamento'); |
67
|
|
|
$payment->message = $this->getObjectUtil()->getProperty($response, 'mensagem_transacao'); |
68
|
|
|
|
69
|
|
|
return $payment; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function order(stdClass $response) |
73
|
|
|
{ |
74
|
|
|
$order = new stdClass(); |
75
|
|
|
$order->orderId = $this->getObjectUtil()->getProperty($response, 'num_pedido'); |
76
|
|
|
|
77
|
|
|
return $order; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function splitRules(stdClass $response) |
81
|
|
|
{ |
82
|
|
|
$splitRules = []; |
83
|
|
|
$split_rules = property_exists($response, 'split_rules') ? $response->split_rules : null; |
84
|
|
|
if (!empty($split_rules)) { |
85
|
|
|
foreach ($split_rules as $split_rule) { |
86
|
|
|
$splitRule = new stdClass(); |
87
|
|
|
$splitRule->rule = $this->getObjectUtil()->getProperty($split_rule, 'rule'); |
88
|
|
|
$splitRule->seller_id = $this->getObjectUtil()->getProperty($split_rule, 'recipient'); |
89
|
|
|
$splitRule->ipag_id = $this->getObjectUtil()->getProperty($split_rule, 'ipag_id'); |
90
|
|
|
$splitRule->amount = $this->getObjectUtil()->getProperty($split_rule, 'amount'); |
91
|
|
|
$splitRule->percentage = $this->getObjectUtil()->getProperty($split_rule, 'percentage'); |
92
|
|
|
$splitRule->liable = $this->getObjectUtil()->getProperty($split_rule, 'liable'); |
93
|
|
|
$splitRule->charge_processing_fee = $this->getObjectUtil()->getProperty($split_rule, 'charge_processing_fee'); |
94
|
|
|
$splitRules[] = $splitRule; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $splitRules; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function creditCard(stdClass $response) |
102
|
|
|
{ |
103
|
|
|
$creditCard = new stdClass(); |
104
|
|
|
if (isset($response->token)) { |
105
|
|
|
$creditCard->token = $this->getObjectUtil()->getProperty($response, 'token'); |
106
|
|
|
$creditCard->last4 = $this->getObjectUtil()->getProperty($response, 'last4'); |
107
|
|
|
$creditCard->expiryMonth = $this->getObjectUtil()->getProperty($response, 'mes'); |
108
|
|
|
$creditCard->expiryYear = $this->getObjectUtil()->getProperty($response, 'ano'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$card = property_exists($response, 'cartao') ? $response->cartao : null; |
112
|
|
|
if (!empty($card)) { |
113
|
|
|
$creditCard->holder = $this->getObjectUtil()->getProperty($card, 'titular'); |
114
|
|
|
$creditCard->number = $this->getObjectUtil()->getProperty($card, 'numero'); |
115
|
|
|
$creditCard->expiry = $this->getObjectUtil()->getProperty($card, 'vencimento'); |
116
|
|
|
$creditCard->brand = $this->getObjectUtil()->getProperty($card, 'bandeira'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $creditCard; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
private function subscription(stdClass $response) |
123
|
|
|
{ |
124
|
|
|
$subscription = new stdClass(); |
125
|
|
|
$subscription->id = $this->getObjectUtil()->getProperty($response, 'id_assinatura'); |
126
|
|
|
$subscription->profileId = $this->getObjectUtil()->getProperty($response, 'profile_id'); |
127
|
|
|
|
128
|
|
|
return $subscription; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
private function antifraud(stdClass $response) |
132
|
|
|
{ |
133
|
|
|
$antifraud = new stdClass(); |
134
|
|
|
$antifraud->id = $this->getObjectUtil()->getProperty($response, 'af_id'); |
135
|
|
|
$antifraud->score = $this->getObjectUtil()->getProperty($response, 'af_score'); |
136
|
|
|
$antifraud->status = $this->getObjectUtil()->getProperty($response, 'af_status'); |
137
|
|
|
$antifraud->message = $this->getObjectUtil()->getProperty($response, 'af_message'); |
138
|
|
|
|
139
|
|
|
return $antifraud; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|