Code Duplication    Length = 56-59 lines in 2 locations

src/merchants/epayservice/EPayServiceMerchant.php 1 location

@@ 21-79 (lines=59) @@
18
 *
19
 * @author Dmytro Naumenko <[email protected]>
20
 */
21
class EPayServiceMerchant extends AbstractMerchant
22
{
23
    /**
24
     * @var \Omnipay\ePayService\Gateway
25
     */
26
    protected $gateway;
27
28
    /**
29
     * @return \Omnipay\Common\GatewayInterface
30
     */
31
    protected function createGateway()
32
    {
33
        return $this->gatewayFactory->build('ePayService', [
34
            'purse' => $this->credentials->getPurse(),
35
            'secret'  => $this->credentials->getKey1(),
36
            'signAlgorithm' => 'sha256'
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 $response
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\ePayService\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->getData()['EPS_ACCNUM'])
77
            ->setTime((new \DateTime())->setTimezone(new \DateTimeZone('UTC')));
78
    }
79
}
80

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 $response
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