Code Duplication    Length = 56-59 lines in 2 locations

src/merchants/interkassa/InterKassaMerchant.php 1 location

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

src/merchants/epayservice/EPayServiceMerchant.php 1 location

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