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