'PayPal SDK when adding client id I get error paypal is not defined
When using the test client-id shown below, everything works:
<body>
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '77.44' // Can reference variables or functions. Example: `value: document.getElementById('...').value`
}
}]
});
},
// Finalize the transaction after payer approval
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// When ready to go live, remove the alert and show a success message within this page. For example:
// var element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
</body>
</html>
But if I change the query parameter client id from test to my sandbox id:
<script src="https://www.paypal.com/sdk/js?client-id=sb-v444pg***79*^@business.example.com¤cy=USD"></script>
I get a console error saying paypal is not defined. Why doesn't my id work?
Solution 1:[1]
client-id=sb-v444pg**79^@business.example.com
That's not a client id, it's a sandbox account email.
Obtain a REST API client id from My Apps & Credentials. When you create a sandbox app you choose the account it's associated with.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Preston PHX |
