0

I am building a Offsite Payment module which contains a Page callback created inside a Controller (website.com/payment-accepted)

After completed form (payment method, address...) on checkout page, The buyer is redirected to another website to pay. Once payment is accepted, the page website.com/payment-accepted is automatically called.

I would like to create new payment when this page is called. Here the code :

  public function MyCallbackPage(OrderInterface $order, Request $request) {
     $payment_storage = $this->entityTypeManager->getStorage('commerce_payment');
        $payment = $payment_storage->create([
          'state' => 'authorization',
          'amount' => $order->getTotalPrice(),
          'payment_gateway' => 'paybox',
          'order_id' => $order->id(),
          'remote_id' => $request->query->get('tx_nid'),
          'remote_state' => $request->query->get('payment_status'),
        ]);
        $payment->save();

}

But i get this error :

Call to a member function getStorage() on null

  • You appear to be rewriting the Drupal Commerce payment gateway API (which already has these callbacks and relevant methods). That won't end well. – Bojan Zivanovic Dec 22 '17 at 19:32
0

ControllerBase::entityTypeManager is a method, not a property:

$payment_storage = $this->entityTypeManager()->getStorage('commerce_payment');
  • Hello Clive, i've updated my post (get a new error message). Thank you. – Webman Dec 21 '17 at 16:46
  • Please don’t change questions once they’ve been anawered, it invalidates the existing answers. If you have a new question, just post a new one. Thanks! – Clive Dec 21 '17 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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