Completed
Push — master ( 576b56...533c2b )
by Dmitry
14:42
created

src/merchants/ikajo/IkajoMerchant.php (2 issues)

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
namespace hiqdev\php\merchant\merchants\ikajo;
4
5
use hiqdev\php\merchant\InvoiceInterface;
6
use hiqdev\php\merchant\merchants\AbstractMerchant;
7
use hiqdev\php\merchant\response\CompletePurchaseResponse;
8
use hiqdev\php\merchant\response\RedirectPurchaseResponse;
9
use Omnipay\Ikajo\Gateway;
10
11
/**
12
 * Class IkajoMerchant.
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16 View Code Duplication
class IkajoMerchant extends AbstractMerchant
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @var Gateway
20
     */
21
    protected $gateway;
22
23
    protected function createGateway()
24
    {
25
        return $this->gatewayFactory->build('Ikajo', [
26
            'purse' => $this->credentials->getPurse(),
27
            'secret'  => $this->credentials->getKey1(),
28
        ]);
29
    }
30
31 3
    /**
32
     * @param InvoiceInterface $invoice
33 3
     * @return RedirectPurchaseResponse
34 3
     */
35 3
    public function requestPurchase(InvoiceInterface $invoice)
36
    {
37
        /**
38
         * @var \Omnipay\Ikajo\Message\PurchaseResponse $response
39
         */
40
        $response = $this->gateway->purchase([
41
            'transactionId' => $invoice->getId(),
42
            'description' => $invoice->getDescription(),
43 1
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
44
            'currency' => $invoice->getCurrency()->getCode(),
45
            'returnUrl' => $invoice->getReturnUrl(),
46
            'cancelUrl' => $invoice->getCancelUrl(),
47
        ])->send();
48 1
49 1
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
50 1
    }
51 1
52 1
    /**
53 1
     * @param array $data
54 1
     * @return CompletePurchaseResponse
55 1
     */
56
    public function completePurchase($data)
57 1
    {
58
        /** @var \Omnipay\Ikajo\Message\CompletePurchaseResponse $response */
59
        $response = $this->gateway->completePurchase($data)->send();
60
61
        return (new CompletePurchaseResponse())
62
            ->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...
63
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
64 1
            ->setTransactionReference($response->getTransactionReference())
65
            ->setTransactionId($response->getTransactionId())
66
            ->setPayer($response->getPayer())
67 1
            ->setTime(new \DateTime($response->getTime()));
68
    }
69
}
70