1 | <?php |
||
16 | class BitPayMerchant extends AbstractMerchant |
||
17 | { |
||
18 | /** |
||
19 | * @return Gateway |
||
20 | */ |
||
21 | protected function createGateway() |
||
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) |
||
74 | |||
75 | } |
||
76 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: