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