| @@ 23-79 (lines=57) @@ | ||
| 20 | * |
|
| 21 | * @author Dmytro Naumenko <[email protected]> |
|
| 22 | */ |
|
| 23 | class OkpayMerchant extends AbstractMerchant |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * @var \Omnipay\Common\GatewayInterface |
|
| 27 | */ |
|
| 28 | protected $gateway; |
|
| 29 | ||
| 30 | protected function createGateway() |
|
| 31 | { |
|
| 32 | return $this->gatewayFactory->build('OKPAY', [ |
|
| 33 | 'purse' => $this->credentials->getPurse(), |
|
| 34 | 'secret' => $this->credentials->getKey1(), |
|
| 35 | 'secret2' => $this->credentials->getKey2(), |
|
| 36 | ]); |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param InvoiceInterface $invoice |
|
| 41 | * @return RedirectPurchaseResponse |
|
| 42 | */ |
|
| 43 | public function requestPurchase(InvoiceInterface $invoice) |
|
| 44 | { |
|
| 45 | /** |
|
| 46 | * @var \Omnipay\BitPay\Message\PurchaseResponse |
|
| 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 | ])->send(); |
|
| 57 | ||
| 58 | return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @param array $data |
|
| 63 | * @return CompletePurchaseResponse |
|
| 64 | */ |
|
| 65 | public function completePurchase($data) |
|
| 66 | { |
|
| 67 | /** @var \Omnipay\OKPAY\Message\CompletePurchaseResponse $response */ |
|
| 68 | $response = $this->gateway->completePurchase($data)->send(); |
|
| 69 | ||
| 70 | return (new CompletePurchaseResponse()) |
|
| 71 | ->setIsSuccessful($response->isSuccessful()) |
|
| 72 | ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
|
| 73 | ->setFee($this->moneyParser->parse($response->getFee(), $response->getCurrency())) |
|
| 74 | ->setTransactionReference($response->getTransactionReference()) |
|
| 75 | ->setTransactionId($response->getTransactionId()) |
|
| 76 | ->setPayer($response->getPayer()) |
|
| 77 | ->setTime($response->getTime()); |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||
| @@ 24-79 (lines=56) @@ | ||
| 21 | * |
|
| 22 | * @author Dmytro Naumenko <[email protected]> |
|
| 23 | */ |
|
| 24 | class PayPalExpressMerchant extends AbstractMerchant |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * @var Gateway |
|
| 28 | */ |
|
| 29 | protected $gateway; |
|
| 30 | ||
| 31 | protected function createGateway() |
|
| 32 | { |
|
| 33 | return $this->gatewayFactory->build('PayPal', [ |
|
| 34 | 'purse' => $this->credentials->getPurse(), |
|
| 35 | 'secret' => $this->credentials->getKey1(), |
|
| 36 | ]); |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param InvoiceInterface $invoice |
|
| 41 | * @return RedirectPurchaseResponse |
|
| 42 | */ |
|
| 43 | public function requestPurchase(InvoiceInterface $invoice) |
|
| 44 | { |
|
| 45 | /** |
|
| 46 | * @var \Omnipay\BitPay\Message\PurchaseResponse |
|
| 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 | ])->send(); |
|
| 57 | ||
| 58 | return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @param array $data |
|
| 63 | * @return CompletePurchaseResponse |
|
| 64 | */ |
|
| 65 | public function completePurchase($data) |
|
| 66 | { |
|
| 67 | /** @var \Omnipay\PayPal\Message\CompletePurchaseResponse $response */ |
|
| 68 | $response = $this->gateway->completePurchase($data)->send(); |
|
| 69 | ||
| 70 | return (new CompletePurchaseResponse()) |
|
| 71 | ->setIsSuccessful($response->isSuccessful()) |
|
| 72 | ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
|
| 73 | ->setFee($this->moneyParser->parse($response->getFee(), $response->getCurrency())) |
|
| 74 | ->setTransactionReference($response->getTransactionReference()) |
|
| 75 | ->setTransactionId($response->getTransactionId()) |
|
| 76 | ->setPayer($response->getPayer()) |
|
| 77 | ->setTime(new \DateTime($response->getTime())); |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||
| @@ 27-85 (lines=59) @@ | ||
| 24 | * |
|
| 25 | * @property \Omnipay\ePayments\Gateway $gateway |
|
| 26 | */ |
|
| 27 | class EpaymentsMerchant extends AbstractMerchant |
|
| 28 | { |
|
| 29 | /** |
|
| 30 | * @return \Omnipay\Common\GatewayInterface |
|
| 31 | */ |
|
| 32 | protected function createGateway() |
|
| 33 | { |
|
| 34 | return $this->gatewayFactory->build('ePayments', [ |
|
| 35 | 'partnerId' => $this->credentials->getPurse(), |
|
| 36 | 'secret' => $this->credentials->getKey1(), |
|
| 37 | ]); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @param InvoiceInterface $invoice |
|
| 42 | * @return RedirectPurchaseResponse |
|
| 43 | */ |
|
| 44 | public function requestPurchase(InvoiceInterface $invoice) |
|
| 45 | { |
|
| 46 | /** |
|
| 47 | * @var PurchaseResponse $response |
|
| 48 | */ |
|
| 49 | $response = $this->gateway->purchase([ |
|
| 50 | 'orderId' => $invoice->getId(), |
|
| 51 | 'details' => $invoice->getDescription(), |
|
| 52 | 'amount' => $this->moneyFormatter->format($invoice->getAmount()), |
|
| 53 | 'currency' => strtolower($invoice->getCurrency()->getCode()), |
|
| 54 | 'returnUrl' => $invoice->getReturnUrl(), |
|
| 55 | 'cancelUrl' => $invoice->getCancelUrl(), |
|
| 56 | ])->send(); |
|
| 57 | ||
| 58 | return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData()); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @param array $data |
|
| 63 | * @return CompletePurchaseResponse |
|
| 64 | */ |
|
| 65 | public function completePurchase($data) |
|
| 66 | { |
|
| 67 | /** @var \Omnipay\ePayments\Message\CompletePurchaseResponse $notification */ |
|
| 68 | $notification = $this->gateway->completePurchase($data)->send(); |
|
| 69 | ||
| 70 | $response = $this->fetchOrderDetails($notification->getOrderId()); |
|
| 71 | ||
| 72 | return (new CompletePurchaseResponse()) |
|
| 73 | ->setIsSuccessful($response->isSuccessful()) |
|
| 74 | ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency())) |
|
| 75 | ->setTransactionReference($response->getTransactionReference()) |
|
| 76 | ->setTransactionId($response->getTransactionId()) |
|
| 77 | ->setPayer($response->getTransactionReference()) |
|
| 78 | ->setTime($response->getPaymentDate()); |
|
| 79 | } |
|
| 80 | ||
| 81 | protected function fetchOrderDetails(string $orderId): DetailsResponse |
|
| 82 | { |
|
| 83 | return $this->gateway->details(['orderId' => $orderId])->send(); |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||