| @@ 15-73 (lines=59) @@ | ||
| 12 | * |
|
| 13 | * @author Dmytro Naumenko <[email protected]> |
|
| 14 | */ |
|
| 15 | 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 | ||
| @@ 16-71 (lines=56) @@ | ||
| 13 | * |
|
| 14 | * @author Dmytro Naumenko <[email protected]> |
|
| 15 | */ |
|
| 16 | class InterKassaMerchant extends AbstractMerchant |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @var Gateway |
|
| 20 | */ |
|
| 21 | protected $gateway; |
|
| 22 | ||
| 23 | protected function createGateway() |
|
| 24 | { |
|
| 25 | return $this->gatewayFactory->build('InterKassa', [ |
|
| 26 | 'checkoutId' => $this->credentials->getPurse(), |
|
| 27 | 'signKey' => $this->credentials->getKey1(), |
|
| 28 | 'signAlgorithm' => 'md5' |
|
| 29 | ]); |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @param InvoiceInterface $invoice |
|
| 34 | * @return RedirectPurchaseResponse |
|
| 35 | */ |
|
| 36 | public function requestPurchase(InvoiceInterface $invoice) |
|
| 37 | { |
|
| 38 | /** |
|
| 39 | * @var \Omnipay\Paxum\Message\PurchaseResponse $response |
|
| 40 | */ |
|
| 41 | $response = $this->gateway->purchase([ |
|
| 42 | 'transactionId' => $invoice->getId(), |
|
| 43 | 'description' => $invoice->getDescription(), |
|
| 44 | 'amount' => $this->moneyFormatter->format($invoice->getAmount()), |
|
| 45 | 'currency' => $invoice->getCurrency()->getCode(), |
|
| 46 | 'returnUrl' => $invoice->getReturnUrl(), |
|
| 47 | 'notifyUrl' => $invoice->getNotifyUrl(), |
|
| 48 | 'cancelUrl' => $invoice->getCancelUrl(), |
|
| 49 | ])->send(); |
|
| 50 | ||
| 51 | return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * @param array $data |
|
| 56 | * @return CompletePurchaseResponse |
|
| 57 | */ |
|
| 58 | public function completePurchase($data) |
|
| 59 | { |
|
| 60 | /** @var \Omnipay\InterKassa\Message\CompletePurchaseResponse $response */ |
|
| 61 | $response = $this->gateway->completePurchase($data)->send(); |
|
| 62 | ||
| 63 | return (new CompletePurchaseResponse()) |
|
| 64 | ->setIsSuccessful($response->isSuccessful()) |
|
| 65 | ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
|
| 66 | ->setTransactionReference($response->getTransactionReference()) |
|
| 67 | ->setTransactionId($response->getTransactionId()) |
|
| 68 | ->setPayer($response->getPayer()) |
|
| 69 | ->setTime((new \DateTime($response->getTime()))->setTimezone(new \DateTimeZone('UTC'))); |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||