Completed
Push — master ( 189007...259fd8 )
by Dmitry
08:51
created

EPayServiceMerchant::completePurchase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 2
1
<?php
2
3
namespace hiqdev\php\merchant\merchants\epayservice;
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
10
/**
11
 * Class EPayServiceMerchant
12
 *
13
 * @author Dmytro Naumenko <[email protected]>
14
 */
15 View Code Duplication
class EPayServiceMerchant extends AbstractMerchant
0 ignored issues
show
Duplication introduced by
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...
16
{
17
    /**
18
     * @var \Omnipay\ePayService\Gateway
19
     */
20
    protected $gateway;
21
22
    /**
23
     * @return \Omnipay\Common\GatewayInterface
24
     */
25
    protected function createGateway()
26
    {
27
        return $this->gatewayFactory->build('ePayService', [
28
            'purse' => $this->credentials->getPurse(),
29
            'secret'  => $this->credentials->getKey1(),
30
            'signAlgorithm' => 'sha256'
31
        ]);
32
    }
33
34
    /**
35
     * @param InvoiceInterface $invoice
36
     * @return RedirectPurchaseResponse
37
     */
38
    public function requestPurchase(InvoiceInterface $invoice)
39
    {
40
        /**
41
         * @var \Omnipay\Paxum\Message\PurchaseResponse $response
42
         */
43
        $response = $this->gateway->purchase([
44
            'transactionId' => $invoice->getId(),
45
            'description' => $invoice->getDescription(),
46
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
47
            'currency' => $invoice->getCurrency()->getCode(),
48
            'returnUrl' => $invoice->getReturnUrl(),
49
            'notifyUrl' => $invoice->getNotifyUrl(),
50
            'cancelUrl' => $invoice->getCancelUrl(),
51
        ])->send();
52
53
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
54
    }
55
56
    /**
57
     * @param array $data
58
     * @return CompletePurchaseResponse
59
     */
60
    public function completePurchase($data)
61
    {
62
        /** @var \Omnipay\ePayService\Message\CompletePurchaseResponse $response */
63
        $response = $this->gateway->completePurchase($data)->send();
64
65
        return (new CompletePurchaseResponse())
66
            ->setIsSuccessful($response->isSuccessful())
0 ignored issues
show
Documentation introduced by
$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...
67
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
68
            ->setTransactionReference($response->getTransactionReference())
69
            ->setTransactionId($response->getTransactionId())
70
            ->setPayer($response->getData()['EPS_ACCNUM'])
71
            ->setTime((new \DateTime())->setTimezone(new \DateTimeZone('UTC')));
72
    }
73
}
74