@@ 23-82 (lines=60) @@ | ||
20 | * |
|
21 | * @author Dmytro Naumenko <[email protected]> |
|
22 | */ |
|
23 | class RoboKassaMerchant extends AbstractMerchant |
|
24 | { |
|
25 | /** |
|
26 | * @var Gateway |
|
27 | */ |
|
28 | protected $gateway; |
|
29 | ||
30 | protected function createGateway() |
|
31 | { |
|
32 | return $this->gatewayFactory->build('RoboKassa', [ |
|
33 | 'purse' => $this->credentials->getPurse(), |
|
34 | 'secretKey' => $this->credentials->getKey1(), |
|
35 | ]); |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * @param InvoiceInterface $invoice |
|
40 | * @return RedirectPurchaseResponse |
|
41 | */ |
|
42 | public function requestPurchase(InvoiceInterface $invoice) |
|
43 | { |
|
44 | /** |
|
45 | * @var \Omnipay\RoboKassa\Message\PurchaseResponse $response |
|
46 | */ |
|
47 | $response = $this->gateway->purchase([ |
|
48 | 'inv_id' => $invoice->getId(), |
|
49 | 'client' => $invoice->getClient(), |
|
50 | 'description' => $invoice->getDescription(), |
|
51 | 'amount' => $this->moneyFormatter->format($invoice->getAmount()), |
|
52 | 'currency' => $invoice->getCurrency()->getCode(), |
|
53 | 'returnUrl' => $invoice->getReturnUrl(), |
|
54 | 'notifyUrl' => $invoice->getNotifyUrl(), |
|
55 | 'cancelUrl' => $invoice->getCancelUrl(), |
|
56 | 'time' => date('c'), |
|
57 | ])->send(); |
|
58 | ||
59 | return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * @param array $data |
|
64 | * @return CompletePurchaseResponse |
|
65 | */ |
|
66 | public function completePurchase($data) |
|
67 | { |
|
68 | /** @var \Omnipay\RoboKassa\Message\CompletePurchaseResponse $response */ |
|
69 | $response = $this->gateway->completePurchase($data)->send(); |
|
70 | ||
71 | return (new CompletePurchaseResponse()) |
|
72 | ->setIsSuccessful($response->isSuccessful()) |
|
73 | ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
|
74 | ->setTransactionReference($response->getTransactionReference()) |
|
75 | ->setTransactionId($response->getTransactionId()) |
|
76 | ->setPayer($response->getData['sender'] ?? $response->getData['email'] ?? '') |
|
77 | ->setTime( |
|
78 | (new \DateTime($response->getTime(), new \DateTimeZone('Europe/Moscow'))) |
|
79 | ->setTimezone(new \DateTimeZone('UTC')) |
|
80 | ); |
|
81 | } |
|
82 | } |
|
83 |
@@ 23-82 (lines=60) @@ | ||
20 | * |
|
21 | * @author Dmytro Naumenko <[email protected]> |
|
22 | */ |
|
23 | class YandexP2pMerchant extends AbstractMerchant |
|
24 | { |
|
25 | /** |
|
26 | * @var P2pGateway |
|
27 | */ |
|
28 | protected $gateway; |
|
29 | ||
30 | protected function createGateway() |
|
31 | { |
|
32 | return $this->gatewayFactory->build('YandexMoney_P2p', [ |
|
33 | 'account' => $this->credentials->getPurse(), |
|
34 | 'password' => $this->credentials->getKey1(), |
|
35 | 'testMode' => $this->credentials->isTestMode() |
|
36 | ]); |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * @param InvoiceInterface $invoice |
|
41 | * @return RedirectPurchaseResponse |
|
42 | */ |
|
43 | public function requestPurchase(InvoiceInterface $invoice) |
|
44 | { |
|
45 | /** |
|
46 | * @var \Omnipay\YandexMoney\Message\p2p\PurchaseResponse $response |
|
47 | */ |
|
48 | $response = $this->gateway->purchase([ |
|
49 | 'transactionId' => $invoice->getId(), |
|
50 | 'description' => $invoice->getDescription(), |
|
51 | 'amount' => $this->moneyFormatter->format($invoice->getAmount()), |
|
52 | 'currency' => $invoice->getCurrency()->getCode(), |
|
53 | 'returnUrl' => $invoice->getReturnUrl(), |
|
54 | 'notifyUrl' => $invoice->getNotifyUrl(), |
|
55 | 'cancelUrl' => $invoice->getCancelUrl(), |
|
56 | 'method' => 'PC', // https://money.yandex.ru/doc.xml?id=526991 |
|
57 | ])->send(); |
|
58 | ||
59 | return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * @param array $data |
|
64 | * @return CompletePurchaseResponse |
|
65 | */ |
|
66 | public function completePurchase($data) |
|
67 | { |
|
68 | /** @var \Omnipay\YandexMoney\Message\p2p\CompletePurchaseResponse $response */ |
|
69 | $response = $this->gateway->completePurchase($data)->send(); |
|
70 | ||
71 | return (new CompletePurchaseResponse()) |
|
72 | ->setIsSuccessful($response->isSuccessful()) |
|
73 | ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
|
74 | ->setTransactionReference($response->getTransactionReference()) |
|
75 | ->setTransactionId($response->getTransactionId()) |
|
76 | ->setPayer($response->getData()['sender'] ?? $response->getData()['email'] ?? '') |
|
77 | ->setTime( |
|
78 | (new \DateTime($response->getTime(), new \DateTimeZone('Europe/Moscow'))) |
|
79 | ->setTimezone(new \DateTimeZone('UTC')) |
|
80 | ); |
|
81 | } |
|
82 | } |
|
83 |