cancel
Showing results for 
Search instead for 
Did you mean: 

Smart button integrations is not working

Options
lotodorado
Contributor
Posted on

Hello

I am integrating in my website a smart button. The code generated in the smart buttons paypal had been copied EXACTLY into the website.

The button is visualize correctly. However the two button (PayPal yellow butt & Credit Card black butt)  are not working correctly because it goes to the paypal sandbox. (??)

Observe this piece of code:

<script src="https://www.paypal.com/sdk/js?client-id=sb&amp;enable-funding=venmo&amp;currency=USD" type="text/javascript" data-sdk-integration-source="button-factory"></script>

 

It should be something as: 

src="https://www.paypal.com/sdk/js?client-id=AU1BBrOhaAumWMGHzHRhSL1p4EqjZSTUrsYSX7oOzYCpdGMQ_CUDgz3Z8y_KxxVwJbtbkkTBbBhaM9YW&enable-funding=venmo&currency=USD" data-sdk-integration-source="button-factory"></script>
<script>

 

How do it change the client-id?.  

Should the right code be generate by PayPal?

 

In advance thanks for your help

 

All code taken from PayPal is following:

 

<div id="smart-button-container">
<div style="text-align: center;">
<div style="margin-bottom: 1.25rem;">
<p>Curso Prueba</p>
<select id="item-options"><option value="Primera Vez">Primera Vez - 5 USD</option><option value="Repetición">Repetición - 3 USD</option></select><select id="quantitySelect" style="visibility: hidden;"></select></div>
<div id="paypal-button-container"></div>
</div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=sb&amp;enable-funding=venmo&amp;currency=USD" type="text/javascript" data-sdk-integration-source="button-factory"></script>
<script type="text/javascript">function initPayPalButton() {
var shipping = 0;
var itemOptions = document.querySelector("#smart-button-container #item-options");
var quantity = parseInt();
var quantitySelect = document.querySelector("#smart-button-container #quantitySelect");
if (!isNaN(quantity)) {
quantitySelect.style.visibility = "visible";
}
var orderDescription = 'Curso Prueba';
if(orderDescription === '') {
orderDescription = 'Item';
}
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'pay',

},
createOrder: function(data, actions) {
var selectedItemDescription = itemOptions.options[itemOptions.selectedIndex].value;
var selectedItemPrice = parseFloat(itemOptions.options[itemOptions.selectedIndex].getAttribute("price"));
var tax = (0 === 0 || false) ? 0 : (selectedItemPrice * (parseFloat(0)/100));
if(quantitySelect.options.length > 0) {
quantity = parseInt(quantitySelect.options[quantitySelect.selectedIndex].value);
} else {
quantity = 1;
}

tax *= quantity;
tax = Math.round(tax * 100) / 100;
var priceTotal = quantity * selectedItemPrice + parseFloat(shipping) + tax;
priceTotal = Math.round(priceTotal * 100) / 100;
var itemTotalValue = Math.round((selectedItemPrice * quantity) * 100) / 100;

return actions.order.create({
purchase_units: [{
description: orderDescription,
amount: {
currency_code: 'USD',
value: priceTotal,
breakdown: {
item_total: {
currency_code: 'USD',
value: itemTotalValue,
},
shipping: {
currency_code: 'USD',
value: shipping,
},
tax_total: {
currency_code: 'USD',
value: tax,
}
}
},
items: [{
name: selectedItemDescription,
unit_amount: {
currency_code: 'USD',
value: selectedItemPrice,
},
quantity: quantity
}]
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
},
onError: function(err) {
console.log(err);
},
}).render('#paypal-button-container');
}
initPayPalButton();</script>

Haven't Found your Answer?

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