3

Folowing is my ajax call in file: Path: /app/code/Nitesh/Module/view/frontend/web/js/view/payment/method-renderer/payment-method.js

$.ajax({
dataType: 'json',
url: url_submit,
data: data,
async : false,
type: 'post',
success: function(result)
{   
    if(result != null) {
        flag_success = 1;
    } else {
        flag_success = 0;
        window.location.assign(url_redirect);
    } 
},
});

My placeOrder() fuction is called when flag_success == 1;

if(flag_success == 1){
      this.placeOrder();
}

Now when I'm redirecting to url_redirect then I want to place an order after getting response from that redirected url.

Means I want to make value of flag_success = 1; after gettting back from that redirected url.

Also If there is any way to call placeOrder() from controller that also helps me. Because I'm getting response of that redirected url there.

If anyone want more information then I will provide.

2

The solution depends on your payment integration implementation. But anyway, it can be done in the following way:

  1. Your payment js component should call set-payment-information API instead payment-information (default method for this WEB API entry point is placeOrder js function) because as I understand you don't want to place an order before you get a response from your payment provider. The example, how to call set-payment-information WEB API you can find in PayPal PayflowPro js component.

  2. After calling set-payment-information WEB API entry point you need to redirect to your payment provider from js component.

  3. In your redirect controller, you can call all required services, which you need. As the example, you can look into Braintree PayPal implementation. It validates quote and uses \Magento\Quote\Api\CartManagementInterface::placeOrder to place order.

| improve this answer | |
  • Thanks alot buddy for ur reply and providing a way to do that. Ok I will see that and tell u after that what is happening. – Nitesh Feb 11 '17 at 11:42
  • Thanks for ur braintree link, from that link I have found solution. Thanks buddy. – Nitesh Feb 12 '17 at 14:30
2

Inside controller where u want to place order:

Use this classes:

use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Model\Quote;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Framework\Controller\ResultFactory;

Create Variables:

protected $cartManagement;
protected $quote;
protected $resultRedirect;

In construct:

parent::__construct($context);
$this->cartManagement = $cartManagement;
$this->quote = $quote;
$this->resultRedirect = $context->getResultFactory();

Place Order:

$this->quote = $this->checkoutSession->getQuote();
$this->quote->getPayment()->setMethod('payfull');
$this->cartManagement->placeOrder($this->quote->getId());

Redirect to success page:

$resultRedirect = $this->resultRedirect->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);

Above code will place order and show success page if order is placed.

| improve this answer | |

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.