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