Code Duplication    Length = 54-54 lines in 2 locations

src/merchants/freekassa/FreeKassaMerchant.php 1 location

@@ 16-69 (lines=54) @@
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16
class FreeKassaMerchant extends AbstractMerchant
17
{
18
    /**
19
     * @var Gateway
20
     */
21
    protected $gateway;
22
23
    protected function createGateway()
24
    {
25
        return $this->gatewayFactory->build('FreeKassa', [
26
            'purse' => $this->credentials->getPurse(),
27
            'secretKey' => $this->credentials->getKey1(),
28
            'secretKey2' => $this->credentials->getKey2(),
29
        ]);
30
    }
31
32
    /**
33
     * @param InvoiceInterface $invoice
34
     * @return RedirectPurchaseResponse
35
     */
36
    public function requestPurchase(InvoiceInterface $invoice)
37
    {
38
        /**
39
         * @var \Omnipay\FreeKassa\Message\PurchaseResponse $response
40
         */
41
        $response = $this->gateway->purchase([
42
            'transaction_id' => $invoice->getId(),
43
            'currency' => $invoice->getCurrency()->getCode(),
44
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
45
            'client' => $invoice->getClient(),
46
        ])->send();
47
48
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
49
    }
50
51
    /**
52
     * @param array $data
53
     * @return CompletePurchaseResponse
54
     */
55
    public function completePurchase($data)
56
    {
57
        /** @var \Omnipay\FreeKassa\Message\CompletePurchaseResponse $response */
58
        $response = $this->gateway->completePurchase($data)->send();
59
60
        return (new CompletePurchaseResponse())
61
            ->setIsSuccessful($response->isSuccessful())
62
            // TODO: !(>_<)! FreeKassa does not indicate currency.
63
            ->setAmount($this->moneyParser->parse($response->getAmount(), 'RUB'))
64
            ->setTransactionReference($response->getTransactionReference())
65
            ->setTransactionId($response->getTransactionId())
66
            ->setPayer($response->getPayer())
67
            ->setTime((new \DateTime($response->getTime()))->setTimezone(new \DateTimeZone('UTC')));
68
    }
69
}
70

src/merchants/robokassa/RoboKassaMerchant.php 1 location

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