cancel
Showing results for 
Search instead for 
Did you mean: 

The page for callbacks from the payment system

The page for callbacks from the payment system

I am writing to the module of payment gateway for Magento 2. I cannot understand what the url for the callback of the payment system. Is there a page created for it? The form for payment system is showing on the page /checkout/onepage/success/

But the url to return, I can not find in the structure chekout and payment modules. Or I can not understand what they are.

3 REPLIES

Re: The page for callbacks from the payment system

Hi @wallone,

 

 

I wasn't able to follow your question. Could you please provide more information / code samples / screenshots to be able to help you?



Best regards.
Gabriel

If my answer was useful, please give "Kudos" to this post.
If my answer helps you to resolve the problem, click on "Accept as Solution".

Re: The page for callbacks from the payment system

I need to send the post method of data to the payment system page. I create the form on the page  /checkout/onepage/success/ 

define(
        [
            'ko',
            'Magento_Checkout/js/view/payment/default',
            'Magento_Checkout/js/model/payment/additional-validators',
            'Magento_Checkout/js/action/redirect-on-success'
        ],
        function (
                ko,
                Component,
                additionalValidators,
                redirectOnSuccessAction) {
            'use strict';
            return Component.extend({
                defaults: {
                    template: '***'
                },
               ***
                /**
                 * Place order.
                 */
                contineOrder: function (data, event) {
                    var self = this;

                    if (event) {
                        event.preventDefault();
                    }
                    if (this.validate() && additionalValidators.validate()) {
                        this.isPlaceOrderActionAllowed(false);
                        if (self.redirectAfterPlaceOrder) {
                            redirectOnSuccessAction.execute();
                        }
                        return true;
                    }
                    return false;
                }
            });
        }
);

checkout_onepage_success.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Success Page</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="***\Payment\Block\Form\CheckoutResult" name="checkout.success" template="form/result_chekout.phtml" cacheable="false"/>
        </referenceContainer>
        <referenceContainer name="order.success.additional.info">
            <block class="***\Payment\Block\Form\CheckoutResult" name="onepage.success.result_chekout"/>
        </referenceContainer>
    </body>
</page>

result_chekout.pthml

<div class="checkout-success">
    <div class="w1 button">
        <form action="<?php echo $block->getApiUrl(); ?>" method="POST">
          <?php foreach ($block->getFormPaymentsArray($block->getLastRealOrder()) as $key => $value){ ?>
            <?php if(is_array($value)){
              foreach ($value as $v) {?>
                <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $v; ?>"></input>
              <?php }?>
            <?php }
            else{?>
              <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"></input>
            <?php }?>
          <?php }?>
          <button class="action primary continue" type="submit">Pay</button>
        </form>
    </div>
</div>

But I don't know on what page to go back to the site from the payment system

Re: The page for callbacks from the payment system

Usually when redirecting to a payment page on a Payment Provider server you have to pass redirectUrl parameter. When Payment Provider processes payment form it triggers redirectUrl of your website. The redirectUrl usually looks like http://www.example.com/paymentcode/redirect/response where "paymentcode" is a name of your payment module. Of course you have to create route.xml to process this request, controller, Complete Command which will get results from Payment provider and change status of an Order to "Processing" or "Suspended Fraud" in case of Fraud checks etc.

 

In the result_checkout.phtml you can add JavaScript responsible for redirecting user to your desired page on a website.