@@ 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 |