Completed
Pull Request — master (#1)
by Dmitry
10:22
created

BitPayMerchant::requestPurchase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 20
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
namespace hiqdev\php\merchant\merchants\bitpay;
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\BitPay\Gateway;
10
11
/**
12
 * Class BitPayAdapter
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16
class BitPayMerchant extends AbstractMerchant
17
{
18
    /**
19
     * @return Gateway
20
     */
21
    protected function createGateway()
22
    {
23
        return $this->gatewayFactory->build('BitPay', [
24
            'token' => $this->credentials->getKey1(),
25
            'privateKey'  => $this->credentials->getKey2(),
26
            'publicKey' => $this->credentials->getKey3(),
27
            'testMode' => $this->getCredentials()->isTestMode()
28
        ]);
29
    }
30
31
    /**
32
     * @param InvoiceInterface $invoice
33
     * @return RedirectPurchaseResponse
34
     */
35
    public function requestPurchase(InvoiceInterface $invoice)
36
    {
37
        /**
38
         * @var \Omnipay\BitPay\Message\PurchaseResponse $response
39
         */
40
        $response = $this->gateway->purchase([
41
            'transactionId' => $invoice->getId(),
42
            'description' => $invoice->getDescription(),
43
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
44
            'currency' => $invoice->getCurrency()->getCode(),
45
            'returnUrl' => $invoice->getReturnUrl(),
46
            'notifyUrl' => $invoice->getNotifyUrl(),
47
            'cancelUrl' => $invoice->getCancelUrl(),
48
        ])->send();
49
50
        $response = new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
51
        $response->setMethod('GET');
52
53
        return $response;
54
    }
55
56
    /**
57
     * @param array $data
58
     * @return CompletePurchaseResponse
59
     */
60
    public function completePurchase($data)
61
    {
62
        /** @var \Omnipay\BitPay\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
            ->setFee($this->moneyParser->parse($response->getFee(), $response->getCurrency()))
69
            ->setTransactionReference($response->getTransactionReference())
70
            ->setTransactionId($response->getTransactionId())
71
            ->setPayer($response->getPayer())
72
            ->setTime(new \DateTime($response->getTime()));
73
    }
74
75
}
76