cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

Item Variables In Smart Button

MapleLeaf4Evr
New Community Member

Hi there,

 

I am struggling through the setup of the new smart payments and javascript.  I am trying to add items to the transaction from my website's shopping cart, but I cannot understand why the variable won't work.

 

        // Render the PayPal button into #paypal-button-container
		var itemsData = '{name: "Basic Class Fee", unit_amount: {currency_code: "CAD",value: "50.00"},quantity: "1"}';
		console.log(itemsData)
        paypal.Buttons({
			
            // Set up the transaction
            createOrder: function(data, actions) {
                return actions.order.create({
                    purchase_units: [{
                        amount: {
							currency_code: "CAD",
							value: "50.00",
							breakdown: {
								item_total: {
								currency_code: "CAD",
								value: "50.00"
							}}
							},
							items: [ (itemsData) ]
                    }]
                });
            },

            // Finalize the transaction
            onApprove: function(data, actions) {
                return actions.order.capture().then(function(details) {
                    // Show a success message to the buyer
                    alert('Transaction completed by ' + details.payer.name.given_name + '!');
                });
            }


        }).render('#paypal-button-container');

 

If I replace the itemsData variable with the string itself, the button works fine, however, as soon as I use the variable, the button breaks and returns a 400 error from PayPal. 

 

Thanks for reading

Login to Me Too
Who Me Too'd this topic