Example: paypal popup php code
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
paypal.Button.render({
env: 'sandbox',
client: {
sandbox: 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
production: '<insert production client id>'
},
commit: true,
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: '30.11',
currency: 'AUD',
details: {
subtotal: '30.00',
tax: '0.07',
shipping: '0.03',
handling_fee: '1.00',
shipping_discount: '-1.00',
insurance: '0.01'
}
},
description: 'The payment transaction description.',
custom: 'EBAY_EMS_90048630024435',
invoice_number: '48787589673',
payment_options: {
allowed_payment_method: 'INSTANT_FUNDING_SOURCE'
},
soft_descriptor: 'ECHI5786786',
item_list: {
items: [
{
name: 'hat',
description: 'Brown hat.',
quantity: '5',
price: '3',
tax: '0.01',
sku: '1',
currency: 'AUD'
},
{
name: 'handbag',
description: 'Black handbag.',
quantity: '1',
price: '15',
tax: '0.02',
sku: 'product34',
currency: 'AUD'
}
],
shipping_address: {
recipient_name: 'Brian Robinson',
line1: '4th Floor',
line2: 'Unit #34',
city: 'Sydney',
country_code: 'AU',
postal_code: '2000',
phone: '011862212345678',
state: 'NSW'
}
}
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
return actions.request.post('complete-order.php', {
paymentID: data.paymentID,
payerID: data.payerID
}).then(function(res) {
if (res == 'error') {
window.alert('Error');
} else {
window.location = 'success.php';
}
});
});
},
onCancel: function(data, actions) {
window.alert('Canceled by user');
},
onError: function(err) {
window.alert('Error: '+err);
}
}, '#paypal-button-container');
</script>
</body>