Answers.Body: <p>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.</p>
  
  <p>This URL should point to the <code>PaymentsController::actionCompletePayment()</code> controller action, but have the param <code>?commerceTransactionHash=YOUR_TRANSACTION_HASH</code> appended to it.</p>
  
  <p>My guess is that the error you are getting is being triggered in <code>PaymentsController::actionCompletePayment()</code> on line 346:</p>
  
  <pre><code>$hash = Craft::$app-&gt;getRequest()-&gt;getParam('commerceTransactionHash');
  
  $transaction = Plugin::getInstance()-&gt;getTransactions()-&gt;getTransactionByHash($hash);
  </code></pre>
  
  <p>Where it is passing null to <code>getTransactionByHash</code>.</p>
  
  <p>Once it is able to get the transaction, it will call your gateway's <code>completePayment</code> method where you can inspect the request data from your gateway.</p>
  
  <p>Hope that helps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-14T13:50:23.497Z
Answers.Text: Ok, this might be a problem in the case of Moneris then.  The redirect URL is added to their configuration page, I am not sending it through with the request.
  
  Could you have a quick look and let me know if there's any other way of doing this Luke?
  https://developer.moneris.com/Documentation/NA/E-Commerce%20Solutions/Hosted%20Solutions/Hosted%20Payment%20Page
Answers.UserDisplayName: Eric Chantigny
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-14T14:18:55.217Z
Answers.Text: I've already setup the return url to go to http://dev.mysite.ca/actions/commerce/payments/complete-payment
Answers.UserDisplayName: Eric Chantigny
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-14T03:03:36.563Z
Answers.LastActivityDate: 2018-09-14T03:48:03.130Z
Answers.LastEditDate: 2018-09-14T03:48:03.130Z
Answers.UserDisplayName: Luke Holder
Body: <p>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.</p>
  
  <p><code>Argument 1 passed to craft\commerce\services\Transactions::getTransactionByHash() must be of the type string, null given</code></p>
  
  <p>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?</p>
  
  <p>Here is the Post Moneris is sending me back:</p>
  
  <p><code>$_POST = [
      'response_order_id' =&gt; '85a6df720018874fde293aa3418e7a97',
      'date_stamp' =&gt; '2018-09-11',
      'time_stamp' =&gt; '08:37:36',
      'bank_transaction_id' =&gt; '660186290010010030',
      'charge_total' =&gt; '88.10',
      'bank_approval_code' =&gt; '945622',
      'response_code' =&gt; '027',
      'iso_code' =&gt; '01',
      'message' =&gt; 'APPROVED           *                    =',
      'trans_name' =&gt; 'purchase',
      'cardholder' =&gt; 'Test Card',
      'f4l4' =&gt; '4242***4242',
      'card' =&gt; 'V',
      'expiry_date' =&gt; '2108',
      'result' =&gt; '1',
      'txn_num' =&gt; '3-0_11',
      'cvd_response_code' =&gt; 'M',
  ];
  </code>
  Thank you!</p>
  
Tags: <plugin-craftcommerce2><payment><omnipay>
Title: getTransactionByHash() must be of the type string, null given
ThreadText: # getTransactionByHash() must be of the type string, null given
  
  (Asked by: username_0 on 2018-09-11)
  
  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!
  
  **Tags:** plugin-craftcommerce2, payment, omnipay
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-14. Score: 1
  
  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.
  
  > **Comments:**
  > **username_0**: Ok, this might be a problem in the case of Moneris then.  The redirect URL is added to their configuration page, I am not sending it through with the request.  Could you have a quick look and let me know if there's any other way of doing this username_1? https://developer.moneris.com/Documentation/NA/E-Commerce%20Solutions/Hosted%20Solutions/Hosted%20Payment%20Page  
  > **username_0**: I've already setup the return url to go to http://dev.mysite.ca/actions/commerce/payments/complete-payment  
  
  ---
  
  