pronamic / wp-pronamic-pay-rabo-smart-pay

Rabo Smart Pay driver for the WordPress payment processing library.
http://www.wp-pay.org/gateways/rabo-smart-pay/
3 stars 4 forks source link

Rabo Smart Pay difference between order ID and transaction ID #21

Closed remcotolsma closed 11 months ago

remcotolsma commented 1 year ago

When starting a Rabo Smart Pay payment, we use the https://betalen.rabobank.nl/omnikassa-api/order/server/api/v2/order endpoint: https://developer.rabobank.nl/product/9981/api/9770#/RaboSmartPayOnlinePaymentAPI_1013/operation/%2Forder%2Fserver%2Fapi%2Fv2%2Forder/post

We receive an omnikassaOrderId in the response:

{
  "redirectURL": "https://betalen.rabobank.nl/omnikassa/nl/payment-brand?token=eyJraWQiOiJFTU8iLCJhbGciOiJFUzI1NiJ9.eyJlbW8iOiJhYWZhMDAxM",
  "omnikassaOrderId": "1d0a95f4-2589-439b-9562-c50aa19f9caf"
}

We save this omnikassaOrderId as transaction ID in the Pronamic payment:

https://github.com/pronamic/wp-pronamic-pay-omnikassa-2/blob/d09ad0e964f907625e11d66dd227a92299da092e/src/Gateway.php#L422-L426

However, there is no overview of 'orders' in the Rabo Smart Pay dashboard, only transactions. The omnikassaOrderId cannot be found at all in the Rabo Smart Pay dashboard. This makes it confusing that we do store and display it as a transaction ID.

Currently we also use the \get_pronamic_payment_by_transaction_id( $omnikassa_order_id ) to find the Pronamic Pay payment:

https://github.com/pronamic/wp-pronamic-pay-omnikassa-2/blob/d09ad0e964f907625e11d66dd227a92299da092e/src/Gateway.php#L557-L575

When requesting order status changes after a webhook call from the Rabo Smart Pay, it is possible to get the transactions of an order returned with the new v2 API: https://betalen.rabobank.nl/omnikassa-api/order/server/api/v2/events/results/merchant.order.status.changed

{
  "moreOrderResultsAvailable": true,
  "orderResults": [
    {
      "merchantOrderId": "order123",
      "omnikassaOrderId": "1d0a95f4-2589-439b-9562-c50aa19f9caf",
      "poiId": "2004",
      "orderStatus": "COMPLETED",
      "orderStatusDateTime": "2018-11-25T12:20:03.157+00:00",
      "errorCode": "cajcodjijuuvof",
      "paidAmount": {
        "amount": 10997,
        "currency": "EUR"
      },
      "totalAmount": {
        "amount": 10997,
        "currency": "EUR"
      },
      "transactions": [
        {
          "transactionId": "22b36073-57a3-4c3d-9585-87f2e55275a5",
          "paymentBrand": "IDEAL",
          "transactionType": "AUTHORIZE",
          "transactionStatus": "SUCCESS",
          "amount": {
            "amount": 10997,
            "currency": "EUR"
          },
          "confirmedAmount": {
            "amount": 10997,
            "currency": "EUR"
          },
          "startDateTime": "2018-03-20T09:12:28Z",
          "lastUpdateTime": "2018-03-20T09:12:28Z"
        }
      ]
    },
    {
      "merchantOrderId": "order123",
      "omnikassaOrderId": "1d0a95f4-2589-439b-9562-c50aa19f9caf",
      "poiId": "2004",
      "orderStatus": "COMPLETED",
      "orderStatusDateTime": "2018-11-25T12:20:03.157+00:00",
      "errorCode": "telibirvameb",
      "paidAmount": {
        "amount": 10997,
        "currency": "EUR"
      },
      "totalAmount": {
        "amount": 10997,
        "currency": "EUR"
      },
      "transactions": [
        {
          "transactionId": "22b36073-57a3-4c3d-9585-87f2e55275a5",
          "paymentBrand": "IDEAL",
          "transactionType": "AUTHORIZE",
          "transactionStatus": "SUCCESS",
          "amount": {
            "amount": 10997,
            "currency": "EUR"
          },
          "confirmedAmount": {
            "amount": 10997,
            "currency": "EUR"
          },
          "startDateTime": "2018-03-20T09:12:28Z",
          "lastUpdateTime": "2018-03-20T09:12:28Z"
        }
      ]
    },
    {
      "merchantOrderId": "order123",
      "omnikassaOrderId": "1d0a95f4-2589-439b-9562-c50aa19f9caf",
      "poiId": "2004",
      "orderStatus": "COMPLETED",
      "orderStatusDateTime": "2018-11-25T12:20:03.157+00:00",
      "errorCode": "nibomd",
      "paidAmount": {
        "amount": 10997,
        "currency": "EUR"
      },
      "totalAmount": {
        "amount": 10997,
        "currency": "EUR"
      },
      "transactions": [
        {
          "transactionId": "22b36073-57a3-4c3d-9585-87f2e55275a5",
          "paymentBrand": "IDEAL",
          "transactionType": "AUTHORIZE",
          "transactionStatus": "SUCCESS",
          "amount": {
            "amount": 10997,
            "currency": "EUR"
          },
          "confirmedAmount": {
            "amount": 10997,
            "currency": "EUR"
          },
          "startDateTime": "2018-03-20T09:12:28Z",
          "lastUpdateTime": "2018-03-20T09:12:28Z"
        }
      ]
    }
  ],
  "signature": "99ca2487243fbad72bbaa456a3219db7b0d2a19777f436cedb3c045e999b86c05001bb0837b43caa3d1757321d00959ac2a161f473a103af72bf440db5147b4a"
}

We currently use the following API endpoint: https://developer.rabobank.nl/product/9981/api/9770#/RaboSmartPayOnlinePaymentAPI_1013/operation/%2Forder%2Fserver%2Fapi%2Fevents%2Fresults%2Fmerchant.order.status.changed/get

https://github.com/pronamic/wp-pronamic-pay-omnikassa-2/blob/d09ad0e964f907625e11d66dd227a92299da092e/src/Client.php#L272-L286

I suggest we do the following things:

The following 4 transactions are all for the same Rabo Smart Pay order:

Scherm­afbeelding 2023-07-27 om 15 20 50

Internal HelpScout ticket: https://secure.helpscout.net/conversation/2310345880/25945/

remcotolsma commented 11 months ago

Wrote an unit test today and fixed some last issues:

https://github.com/pronamic/wp-pronamic-pay-omnikassa-2/blob/3560964c8c2f78bd14df116aa407f701fa562cec/tests/src/WebhookControllerTest.php#L65-L154