Payment processing & Redirect page?

myemcertain
Contributor
Contributor

Hi,

I integrated a Smart Payment Button into my site, but 1) the payment did not go through; 2) it is not directing to the 'thankyou' page.  I'm not a coder and am feeling lost.  Would you please help troubleshoot?  

Thanks!

Garrett

 

 

<div id="smart-button-container">
      <div style="text-align: center;">
        <div id="paypal-button-container"></div>
      </div>
    </div>
  <script src="https://www.paypal.com/sdk/js?client-id=AYQEiLhOfhtm3pAZaHsaafpnP6DwQUabWdV_irJun929s4QIMmOwWzEGhgF3RUVY5X3IIrFYsCndOn3a&enable-funding=venmo&currency=USD" data-sdk-integration-source="button-factory"></script>
  <script>
    function initPayPalButton() {
      paypal.Buttons({
        style: {
          shape: 'rect',
          color: 'white',
          layout: 'vertical',
          label: 'paypal',
          
        },

        createOrder: function(data, actions) {
          return actions.order.create({
            purchase_units: [{"description":"3-month Membership","amount":{"currency_code":"USD","value":1}}]
          });
        },

        onApprove: function(data, actions) {
          return actions.order.capture().then(function(orderData) {
            
            // Full available details
            console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));

            // Show a success message within this page, e.g.
            //const element = document.getElementById('paypal-button-container');
            //element.innerHTML = '';
            //element.innerHTML = '<h3>Thank you for your payment!</h3>';

            // Or go to another URL:  
            actions.redirect('thankyou');
            
          });
        },

        onError: function(err) {
          console.log(err);
        }
      }).render('#paypal-button-container');
    }
    initPayPalButton();
  </script>

 

 

Login to Me Too
2 REPLIES 2

MTS_Chiranjeevi
Moderator
Moderator

Good day @myemcertain,

 

Thank you for posting to the PayPal community.

 

Please contact your internal website developer or support of eCommerce to refer the below detailed guide link and pass the "return_url". 

 

https://developer.paypal.com/docs/api/orders/v2/#definition-application_context 

 

https://developer.paypal.com/docs/api/orders/v2/#orders_create

 

curl -v -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-H "PayPal-Request-Id: ******" \
-d '{
"intent": "CAPTURE",
"purchase_units": [
{
"reference_id": "******",
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
],
"payment_source": {
"paypal": {
"experience_context": {
"payment_method_preference": "IMMEDIATE_PAYMENT_REQUIRED",
"payment_method_selected": "PAYPAL",
"brand_name": "EXAMPLE INC",
"locale": "en-US",
"landing_page": "LOGIN",
"shipping_preference": "SET_PROVIDED_ADDRESS",
"user_action": "PAY_NOW",
"return_url": "https://example.com/returnUrl",
"cancel_url": "https://example.com/cancelUrl"
}
}
}
}'

 

Guide link - https://developer.paypal.com/docs/checkout/standard/ 

 

Sincerely,

Chiranjeevi

PayPal/Braintree MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too

myemcertain
Contributor
Contributor

Thank you for the response.  Sadly, I don't have a developer (that's why I'm using Wix), and am doing my best to implement this myself.  Where in my code should I insert your suggested code?   

Thanks,

Garrett

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.