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
|
|
|
if (isset($response->token)) { |
26
|
|
|
$transaction->creditCard = $this->creditCard($response); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (isset($response->id_assinatura)) { |
30
|
|
|
$transaction->subscription = $this->subscription($response); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $transaction; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
private function getObjectUtil() |
37
|
|
|
{ |
38
|
|
|
if (is_null($this->objectUtil)) { |
39
|
|
|
$this->objectUtil = new ObjectUtil(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $this->objectUtil; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function transaction(stdClass $response) |
46
|
|
|
{ |
47
|
|
|
$transaction = new stdClass(); |
48
|
|
|
$transaction->tid = $this->getObjectUtil()->getProperty($response, 'id_transacao'); |
49
|
|
|
$transaction->amount = $this->getObjectUtil()->getProperty($response, 'valor'); |
50
|
|
|
$transaction->acquirer = $this->getObjectUtil()->getProperty($response, 'operadora'); |
51
|
|
|
$transaction->acquirerMessage = $this->getObjectUtil()->getProperty($response, 'operadora_mensagem'); |
52
|
|
|
$transaction->urlAthentication = $this->getObjectUtil()->getProperty($response, 'url_autenticacao'); |
53
|
|
|
$transaction->payment = $this->payment($response); |
54
|
|
|
$transaction->order = $this->order($response); |
55
|
|
|
|
56
|
|
|
$transaction->error = $this->getObjectUtil()->getProperty($response, 'code'); |
57
|
|
|
$transaction->errorMessage = $this->getObjectUtil()->getProperty($response, 'message'); |
58
|
|
|
|
59
|
|
|
return $transaction; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function payment(stdClass $response) |
63
|
|
|
{ |
64
|
|
|
$payment = new stdClass(); |
65
|
|
|
$payment->status = $this->getObjectUtil()->getProperty($response, 'status_pagamento'); |
66
|
|
|
$payment->message = $this->getObjectUtil()->getProperty($response, 'mensagem_transacao'); |
67
|
|
|
|
68
|
|
|
return $payment; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function order(stdClass $response) |
72
|
|
|
{ |
73
|
|
|
$order = new stdClass(); |
74
|
|
|
$order->orderId = $this->getObjectUtil()->getProperty($response, 'num_pedido'); |
75
|
|
|
|
76
|
|
|
return $order; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function creditCard(stdClass $response) |
80
|
|
|
{ |
81
|
|
|
$creditCard = new stdClass(); |
82
|
|
|
$creditCard->token = $this->getObjectUtil()->getProperty($response, 'token'); |
83
|
|
|
$creditCard->last4 = $this->getObjectUtil()->getProperty($response, 'last4'); |
84
|
|
|
$creditCard->expiryMonth = $this->getObjectUtil()->getProperty($response, 'mes'); |
85
|
|
|
$creditCard->expiryYear = $this->getObjectUtil()->getProperty($response, 'ano'); |
86
|
|
|
|
87
|
|
|
return $creditCard; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function subscription(stdClass $response) |
91
|
|
|
{ |
92
|
|
|
$subscription = new stdClass(); |
93
|
|
|
$subscription->id = $this->getObjectUtil()->getProperty($response, 'id_assinatura'); |
94
|
|
|
$subscription->profileId = $this->getObjectUtil()->getProperty($response, 'profile_id'); |
95
|
|
|
|
96
|
|
|
return $subscription; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|