pronamic / wp-pronamic-pay

The Pronamic Pay plugin allows you to easily accept payments with payment methods like credit card, iDEAL, Bancontact and Sofort through a variety of payment providers on your WordPress website.
https://pronamicpay.com
34 stars 14 forks source link

Improve Buckaroo unchecked `AllowTestTransactions` setting handling #166

Closed remcotolsma closed 3 years ago

remcotolsma commented 3 years ago

Per Buckaroo website there is a setting to allow test transactions:

Accepteer testtransacties

plaza buckaroo nl_Configuration_WebSite_Index_

Wanneer testtransacties geaccepteerd mogen worden is het mogelijk om transacties te sturen naar de test-gateway en deze zullen worden verwerkt als test-transacties. Wanneer ze naar de live-gateway worden gestuurd worden ze verwerkt als live transacties. Wanneer testtransacties niet geaccepteerd mogen worden is het alleen mogelijk om transacties naar de live-gateway te sturen. Elke transactie die naar de test-gateway wordt gestuurd zal worden afgewezen. Dit maakt het mogelijk om te voorkomen dat ongewenst testtransacties terechtkomen in uw live-systeem.

When this setting is unchecked a test transaction in test mode from the Pronamic Pay gateway confiugration post settings will trigger the following exception: Unsupported Buckaroo action::

https://github.com/wp-pay-gateways/buckaroo/blob/a438b2c863cfb51d2272eac9ecd3371976bd370c/src/Gateway.php#L405-L415

We can improve this exception:

object(stdClass)[12769]
  public 'Key' => string '076D08E6AC294FBE90DDDC5A6D0BD4A4' (length=32)
  public 'Status' => 
    object(stdClass)[12775]
      public 'Code' => 
        object(stdClass)[12777]
          public 'Code' => int 490
          public 'Description' => string 'Failed' (length=6)
      public 'SubCode' => 
        object(stdClass)[12778]
          public 'Code' => string 'S072' (length=4)
          public 'Description' => string 'Test mode is not allowed for the current account. Please make sure the account is active or in testmode.' (length=104)
      public 'DateTime' => string '2021-06-25T10:56:48' (length=19)
  public 'RequiredAction' => null
  public 'Services' => null
  public 'CustomParameters' => null
  public 'AdditionalParameters' => null
  public 'RequestErrors' => null
  public 'Invoice' => string '457' (length=3)
  public 'ServiceCode' => string 'ideal' (length=5)
  public 'IsTest' => boolean true
  public 'Currency' => string 'EUR' (length=3)
  public 'AmountDebit' => float 1056
  public 'TransactionType' => null
  public 'MutationType' => int 0
  public 'RelatedTransactions' => null
  public 'ConsumerMessage' => null
  public 'Order' => null
  public 'IssuingCountry' => null
  public 'StartRecurrent' => boolean false
  public 'Recurring' => boolean false
  public 'CustomerName' => null
  public 'PayerHash' => null
  public 'PaymentKey' => string 'E2CCB93AE45C49E5A74604931DC28C45' (length=32)

https://dev.buckaroo.nl/PaymentMethods

Should we throw an Exception when Status.Code.Code = 490?

Reported by @kjtolsma.

rvdsteege commented 3 years ago

Should we throw an Exception when Status.Code.Code = 490?

Yes, improved error handling in https://github.com/wp-pay-gateways/buckaroo/commit/c655ac552bfe1e52a70907b09c96a590a5b548c3

remcotolsma commented 3 years ago

@rvdsteege asked on Slack, what will happen if RequiredAction is null?

https://github.com/wp-pay-gateways/buckaroo/blob/c655ac552bfe1e52a70907b09c96a590a5b548c3/src/Gateway.php#L418-L451

rvdsteege commented 3 years ago

If RequiredAction is null, the payment action URL will not be set (as there is none) and this will result in an exception being throwed:

Action URL is empty, can not redirect.

https://github.com/pronamic/wp-pay-core/blob/79dae9bacc6969f082c741372ba264117c4cb2fc/src/Core/Gateway.php#L472-L476