Completed
Push — master ( 259fd8...a43b07 )
by Andrii
03:33
created

src/merchants/robokassa/RoboKassaMerchant.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Generalization over Omnipay and Payum
4
 *
5
 * @link      https://github.com/hiqdev/php-merchant
6
 * @package   php-merchant
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\merchant\merchants\robokassa;
12
13
use hiqdev\php\merchant\InvoiceInterface;
14
use hiqdev\php\merchant\merchants\AbstractMerchant;
15
use hiqdev\php\merchant\response\CompletePurchaseResponse;
16
use hiqdev\php\merchant\response\RedirectPurchaseResponse;
17
use Omnipay\RoboKassa\Gateway;
18
19
/**
20
 * Class RoboKassaMerchant.
21
 *
22
 * @author Dmytro Naumenko <[email protected]>
23
 */
24 View Code Duplication
class RoboKassaMerchant extends AbstractMerchant
25
{
26
    /**
27
     * @var Gateway
28
     */
29
    protected $gateway;
30
31 3
    protected function createGateway()
32
    {
33 3
        return $this->gatewayFactory->build('RoboKassa', [
34 3
            'purse' => $this->credentials->getPurse(),
35 3
            'secretKey' => $this->credentials->getKey1(),
36 3
            'secretKey2' => $this->credentials->getKey2(),
37
        ]);
38
    }
39
40
    /**
41
     * @param InvoiceInterface $invoice
42
     * @return RedirectPurchaseResponse
43
     */
44 1
    public function requestPurchase(InvoiceInterface $invoice)
45
    {
46
        /**
47
         * @var \Omnipay\RoboKassa\Message\PurchaseResponse
48
         */
49 1
        $response = $this->gateway->purchase([
50 1
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
51 1
            'transaction_id' => $invoice->getId(),
52 1
            'description' => $invoice->getDescription(),
53 1
            'currency' => $invoice->getCurrency()->getCode(),
54 1
            'client' => $invoice->getClient(),
55 1
        ])->send();
56
57 1
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
58
    }
59
60
    /**
61
     * @param array $data
62
     * @return CompletePurchaseResponse
63
     */
64 1
    public function completePurchase($data)
65
    {
66
        /** @var \Omnipay\RoboKassa\Message\CompletePurchaseResponse $response */
67 1
        $response = $this->gateway->completePurchase($data)->send();
68
69 1
        return (new CompletePurchaseResponse())
70 1
            ->setIsSuccessful($response->isSuccessful())
0 ignored issues
show
$response->isSuccessful() is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71 1
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
72 1
            ->setTransactionReference($response->getTransactionReference())
73 1
            ->setTransactionId($response->getTransactionId())
74 1
            ->setPayer($response->getPayer())
75 1
            ->setTime((new \DateTime())->setTimezone(new \DateTimeZone('UTC')));
76
    }
77
}
78