I'm building my first Payment Gateway (offsite gateway) for Commerce 2. This one is for Moneris. I'm hitting an error when the page returns the response.

Argument 1 passed to craft\commerce\services\Transactions::getTransactionByHash() must be of the type string, null given

I'm pretty sure I need to do something in completePurchase with the response given, but I don't really understand where to start. I've looked at Mollie and Paypal Express for exemples and I can't figure it out. Can anyone point me in the right direction?

Here is the Post Moneris is sending me back:

$_POST = [ 'response_order_id' => '85a6df720018874fde293aa3418e7a97', 'date_stamp' => '2018-09-11', 'time_stamp' => '08:37:36', 'bank_transaction_id' => '660186290010010030', 'charge_total' => '88.10', 'bank_approval_code' => '945622', 'response_code' => '027', 'iso_code' => '01', 'message' => 'APPROVED * =', 'trans_name' => 'purchase', 'cardholder' => 'Test Card', 'f4l4' => '4242***4242', 'card' => 'V', 'expiry_date' => '2108', 'result' => '1', 'txn_num' => '3-0_11', 'cvd_response_code' => 'M', ]; Thank you!

When you redirect to the gateway's site to accept payment, within the data they receive, they usually ask for the URL to return to after payment is made.

This URL should point to the PaymentsController::actionCompletePayment() controller action, but have the param ?commerceTransactionHash=YOUR_TRANSACTION_HASH appended to it.

My guess is that the error you are getting is being triggered in PaymentsController::actionCompletePayment() on line 346:

$hash = Craft::$app->getRequest()->getParam('commerceTransactionHash');

$transaction = Plugin::getInstance()->getTransactions()->getTransactionByHash($hash);

Where it is passing null to getTransactionByHash.

Once it is able to get the transaction, it will call your gateway's completePayment method where you can inspect the request data from your gateway.

Hope that helps.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.