How to send and receive custom_id in javascript ?

whitedragon101
Contributor
Contributor

 

I am setting up a purchase that has a local order_id and I want to be able to link that id to the purchase.  The support documents say you can send a custom_id.  I am sending it using the code below but I am not sure if the format is correct or if it is getting sent.  

The main issue is I don't know how to get the custom_id back from the return data.  I am outputting the full contents of data and details to the console on return and neither contain the custom_id.

 

1) Is the code correct for sending the custom_id ?

2) How do I get the custom_id back from the returning order to make sure its the same transaction?

 

 

 <script>
                          paypal.Buttons({
                            createOrder: function(data, actions) {
                              return actions.order.create({
                                purchase_units: [{
                                  amount: { 
                                      value: '20'
                                  },custom_id: '55',
                                  
                                }]
                              });
                            },
                            onApprove: function(data, actions) {
                              return actions.order.capture().then(function(details) 
                              {
                                console.log("DETAILS");
				console.log(details);
                                console.log("DATA");
                                console.log(data);

                                alert("Transaction completed by order id =" + data.orderID+ " our local id = " +  custom_id?????  );

								payPalConfirm(data.orderID); // my ajax call to confirm the transaction via php

                                // Call your server to save the transaction
                                return fetch('/paypal-transaction-complete', {
                                  method: 'post',
                                  headers: {
                                    'content-type': 'application/json'
                                  },
                                  body: JSON.stringify({
                                    orderID: data.orderID
                                  })
                                });
                              });
                            }
                          }).render('#paypal-button-container');
                        </script>

 

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

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