Not able to place the order using paypal in magento 2 rest

前端 未结 3 1142
臣服心动
臣服心动 2020-12-21 01:22

I am developing an e-commerce mobiloe application using magento 2 rest apis only.This is the flow for making the REST API calls for order placement.

相关标签:
3条回答
  • 2020-12-21 01:40

    If you use the below to run a post query replace runPostQuery with your curl request. this will pass a token that already has been successful to magento 2.

     $payment['paymentMethod'] = ['method' =>'paypal_express',
                   'additional_data' => array (
                       'paypal_express_checkout_token' => $request->query->get('token'),
                       'paypal_express_checkout_redirect_required' => false,
                       'paypal_express_checkout_payer_id' => $request->query->get('PayerID')
                   )];
    
    
               $completedPayment = $this->runPostQuery('carts/mine/payment-information', $headers, json_encode($payment));
    

    You will need to create a plugin to add the last transaction id to the payment see the above comment, but the above payload to payment-information will allow you to get past _placeOrder function in Paypal\Model\Express.php

    The paypal_express_checkout_token is the token passed back to the browser from paypal same as PayerId this allows to check the payment, which will return successful and not require a redirect, but is not the payment reference just the action token.

    0 讨论(0)
  • 2020-12-21 02:03

    In case someone still looking the solution.

    In the time I'm answering this, You will need to create a Magento 2 module to process the payment ID.

    After you receive the response from in example Paypal android SDK.

    Below is the JSON format that you can send to Magento endpoint :

    • for logged user : PUT /V1/carts/mine/order
    • for guest : PUT /V1/guest-carts/:cartId/order

    Referrence : http://devdocs.magento.com/swagger

    The "paypal_express_payment_payload" is just a custom attribute to hold the paypal payment response previously from android SDK.

    {
        "paymentMethod": {
            "method": "paypal_express",
            "additional_data": {
                "paypal_express_payment_payload": "{\"create_time\":\"2017-06-15T23:13:52Z\",\"id\":\"PAY-2LB41725NU654612TLFBRIUQ\",\"intent\":\"sale\",\"state\":\"approved\"}"
            }
        }
    }
    

    To process the "paypal_express_payment_payload" data, you can implement a Interceptor in your Magento 2 module :

    di.xml

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="Magento\Paypal\Model\Express">
            <plugin name="mymodule_magento_paypal_model_express_plugin" 
                    type="Mycompanyorpersonal\Mymodule\Plugin\Paypal\Model\Express" 
                    sortOrder="99999" 
                    disabled="false" />
        </type>
    </config>
    

    Mycompanyorpersonal\Mymodule\Plugin\Paypal\Model\Express.php

    You can find the full PHP codes in my following gist : https://gist.github.com/feelinc/de817030e00adc7ff7001de1807c1835

    0 讨论(0)
  • 2020-12-21 02:04

    Paypal Express payment method doesn't support online capturing. There is no way to get a full order creation flow like on Checkout via Magento API interface. It is impossible to change the order state and process payments. As a workaround try the following:

    1. Create a custom payment method
    2. Enable for REST API only(Not on website checkout page)
    3. While making payment using rest api use this method (after successful payment using you android/ios SDK)
    4. After placing the order make send transaction id(PAY-xxxxx) return by paypal sdk payment to save trasaction.(tell your server side tio implement this call).

    I am writting a complete atrticle regarding this step by step. I will let you know when it is done.

    0 讨论(0)
提交回复
热议问题