Code Duplication    Length = 56-57 lines in 2 locations

src/merchants/okpay/OkpayMerchant.php 1 location

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

src/merchants/paypal/PayPalExpressMerchant.php 1 location

@@ 23-78 (lines=56) @@
20
 *
21
 * @author Dmytro Naumenko <[email protected]>
22
 */
23
class PayPalExpressMerchant extends AbstractMerchant
24
{
25
    /**
26
     * @var Gateway
27
     */
28
    protected $gateway;
29
30
    protected function createGateway()
31
    {
32
        return $this->gatewayFactory->build('PayPal', [
33
            'purse' => $this->credentials->getPurse(),
34
            'secret' => $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\BitPay\Message\PurchaseResponse $response
46
         */
47
        $response = $this->gateway->purchase([
48
            'transactionId' => $invoice->getId(),
49
            'description' => $invoice->getDescription(),
50
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
51
            'currency' => $invoice->getCurrency()->getCode(),
52
            'returnUrl' => $invoice->getReturnUrl(),
53
            'notifyUrl' => $invoice->getNotifyUrl(),
54
            'cancelUrl' => $invoice->getCancelUrl(),
55
        ])->send();
56
57
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
58
    }
59
60
    /**
61
     * @param array $data
62
     * @return CompletePurchaseResponse
63
     */
64
    public function completePurchase($data)
65
    {
66
        /** @var \Omnipay\PayPal\Message\CompletePurchaseResponse $response */
67
        $response = $this->gateway->completePurchase($data)->send();
68
69
        return (new CompletePurchaseResponse())
70
            ->setIsSuccessful($response->isSuccessful())
71
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
72
            ->setFee($this->moneyParser->parse($response->getFee(), $response->getCurrency()))
73
            ->setTransactionReference($response->getTransactionReference())
74
            ->setTransactionId($response->getTransactionId())
75
            ->setPayer($response->getPayer())
76
            ->setTime(new \DateTime($response->getTime()));
77
    }
78
}
79