Can't find why order is being rejected (sb, js)

JayReeve
Contributor
Contributor

My website takes reservations for "Supertitles" for American orchestras wanting to project text or translations coordinated with sung lyrics. I have gotten my code to work a few times when I have copied examples verbatim, but as soon as I start putting in my own values, I get 400's or 422's. I would like to show you what I have, and see if you can spot where I'm going awry. Here are the values being submitted, followed by my code, which resides in a function called to render the button:

 

Screen Shot 2020-12-19 at 2.34.37 AM.pngScreen Shot 2020-12-19 at 2.35.30 AM.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    paypal.Buttons({
 
        style: {layout: "vertical", color: "gold", shape: "pill", label: "pay"},
 
        createOrder: function (data, actions) {
            return actions.order.create({
                purchase_units: [{
                    reference_id: invoice,
                    custom_id: customer,
                    soft_descriptor: "TastefulTitles",
                    amount: {
                        currency_code: "USD",
                        value: total,
                        breakdown: {
                            item_total: {currency_code: "USD", value: subtotal},
                            discount: {currency_code: "USD", value: discount},
                            tax: {currency_code: "USD", value: tax}
                        }
                    },
 
                    items: a_itemList,
 
                    shipping: {
                        method:  "United States Postal Service",
                        name: {full_name: to},
                        address: address
                    }
                }],
 
                application_context: {
                    brand_name: "TastefulTitles.com",
                    //shipping_preference: "SET_PROVIDED_ADDRESS",
                    user_action: "PAY_NOW"
                }
            });
        },
 
        onApprove: function (data, actions) {
            return actions.order.capture().then(function (details) {
                alert("Transaction completed by " + details.payer.name.given_name);
                //Call your server to save the transaction
                return fetch("/api/paypal-transaction-complete", {
                    method: "post",
                    headers: {
                        "content-type": "application/json"
                    },
                    body: JSON.stringify({
                        orderID: data.orderID
                    })
                });
            });
        }
    }).render('#paypal-button-container');
 

I have omitted the code that builds the objects and fills the variables, as it should be clear from the values shown whether they are properly constructed. For testing I'm using a random number for reference_id, so as not to be submitting repeat orders.

 

For now, I'm not concerned with the onApprove: code; I'll tackle it once I can get the order correct. There's probably something very simple that should be obvious, but I need some more experienced eyes to find it. Any help will be greatly appreciated!

 

FWIW, I have a fair amount of experience as a hobbyist programmer, but am relatively new to javascript. This is my first time dealing with js objects.

Login to Me Too
1 REPLY 1

JayReeve
Contributor
Contributor

Can someone please explain why my screenshots have disappeared? No one will be able to help me without their information. Am I in the wrong venue to get an answer to my question?

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.