1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hiqdev\php\merchant\merchants\epayservice; |
4
|
|
|
|
5
|
|
|
use hiqdev\php\merchant\InvoiceInterface; |
6
|
|
|
use hiqdev\php\merchant\merchants\AbstractMerchant; |
7
|
|
|
use hiqdev\php\merchant\response\CompletePurchaseResponse; |
8
|
|
|
use hiqdev\php\merchant\response\RedirectPurchaseResponse; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class EPayServiceMerchant |
12
|
|
|
* |
13
|
|
|
* @author Dmytro Naumenko <[email protected]> |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class EPayServiceMerchant extends AbstractMerchant |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \Omnipay\ePayService\Gateway |
19
|
|
|
*/ |
20
|
|
|
protected $gateway; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return \Omnipay\Common\GatewayInterface |
24
|
|
|
*/ |
25
|
|
|
protected function createGateway() |
26
|
|
|
{ |
27
|
|
|
return $this->gatewayFactory->build('ePayService', [ |
28
|
|
|
'purse' => $this->credentials->getPurse(), |
29
|
|
|
'secret' => $this->credentials->getKey1(), |
30
|
|
|
'signAlgorithm' => 'sha256' |
31
|
|
|
]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param InvoiceInterface $invoice |
36
|
|
|
* @return RedirectPurchaseResponse |
37
|
|
|
*/ |
38
|
|
|
public function requestPurchase(InvoiceInterface $invoice) |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var \Omnipay\Paxum\Message\PurchaseResponse $response |
42
|
|
|
*/ |
43
|
|
|
$response = $this->gateway->purchase([ |
44
|
|
|
'transactionId' => $invoice->getId(), |
45
|
|
|
'description' => $invoice->getDescription(), |
46
|
|
|
'amount' => $this->moneyFormatter->format($invoice->getAmount()), |
47
|
|
|
'currency' => $invoice->getCurrency()->getCode(), |
48
|
|
|
'returnUrl' => $invoice->getReturnUrl(), |
49
|
|
|
'notifyUrl' => $invoice->getNotifyUrl(), |
50
|
|
|
'cancelUrl' => $invoice->getCancelUrl(), |
51
|
|
|
])->send(); |
52
|
|
|
|
53
|
|
|
return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $data |
58
|
|
|
* @return CompletePurchaseResponse |
59
|
|
|
*/ |
60
|
|
|
public function completePurchase($data) |
61
|
|
|
{ |
62
|
|
|
/** @var \Omnipay\ePayService\Message\CompletePurchaseResponse $response */ |
63
|
|
|
$response = $this->gateway->completePurchase($data)->send(); |
64
|
|
|
|
65
|
|
|
return (new CompletePurchaseResponse()) |
66
|
|
|
->setIsSuccessful($response->isSuccessful()) |
|
|
|
|
67
|
|
|
->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
68
|
|
|
->setTransactionReference($response->getTransactionReference()) |
69
|
|
|
->setTransactionId($response->getTransactionId()) |
70
|
|
|
->setPayer($response->getData()['EPS_ACCNUM']) |
71
|
|
|
->setTime((new \DateTime())->setTimezone(new \DateTimeZone('UTC'))); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.