paypal popup php code

Solutions on MaxInterview for paypal popup php code by the best coders in the world

showing results for - "paypal popup php code"
Simona
06 Oct 2016
1<!DOCTYPE html>
2
3<head>
4 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <script src="https://www.paypalobjects.com/api/checkout.js"></script>
7</head>
8
9<body>
10 <div id="paypal-button-container"></div>
11
12 <script>
13 paypal.Button.render({
14 // selection for sandbox or production
15 env: 'sandbox', // sandbox | production
16 // PayPal Client IDs, these are the example defaults - replace with your own
17 client: {
18 sandbox: 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
19 production: '<insert production client id>'
20 },
21 // Show the buyer a 'Pay Now' button in the checkout flow
22 commit: true,
23 // payment() is called when the button is clicked
24 payment: function(data, actions) {
25
26 // Make a call to the REST api to create the payment
27 return actions.payment.create({
28 payment: {
29 transactions: [
30 {
31 // This is your cart totals, shipping, tax etc, just remove items you dont need
32 amount: { 
33 total: '30.11', 
34 currency: 'AUD',
35 details: {
36 subtotal: '30.00',
37 tax: '0.07',
38 shipping: '0.03',
39 handling_fee: '1.00',
40 shipping_discount: '-1.00',
41 insurance: '0.01'
42 }
43 },
44 description: 'The payment transaction description.',
45 custom: 'EBAY_EMS_90048630024435',
46 invoice_number: '48787589673',
47 payment_options: {
48 allowed_payment_method: 'INSTANT_FUNDING_SOURCE'
49 },
50 soft_descriptor: 'ECHI5786786',
51 item_list: {
52 // Loop through your cart here, must add up to sub total set above
53 items: [
54 {
55 name: 'hat',
56 description: 'Brown hat.',
57 quantity: '5',
58 price: '3',
59 tax: '0.01',
60 sku: '1',
61 currency: 'AUD'
62 },
63 {
64 name: 'handbag',
65 description: 'Black handbag.',
66 quantity: '1',
67 price: '15',
68 tax: '0.02',
69 sku: 'product34',
70 currency: 'AUD'
71 }
72 ],
73 shipping_address: {
74 recipient_name: 'Brian Robinson',
75 line1: '4th Floor',
76 line2: 'Unit #34',
77 city: 'Sydney',
78 country_code: 'AU',
79 postal_code: '2000',
80 phone: '011862212345678',
81 state: 'NSW'
82 }
83
84 }
85 
86 }
87 ]
88 }
89 });
90 },
91 onAuthorize: function(data, actions) {
92 // Make a call to the REST api to execute the payment
93 return actions.payment.execute().then(function() {
94 // If the transaction is successful on Paypal, you can then Post to a script to run actions on your site like emailing the user etc
95 return actions.request.post('complete-order.php', {
96 paymentID: data.paymentID,
97 payerID: data.payerID
98 }).then(function(res) {
99 if (res == 'error') {
100 // Show an alter if there was an error 
101 window.alert('Error');
102 } else {
103 // Redirect to a success page if everything completed okay
104 window.location = 'success.php'; 
105 }
106 });
107 });
108 },
109 onCancel: function(data, actions) {
110 // Show an alert if user cancels
111 window.alert('Canceled by user');
112 },
113 onError: function(err) {
114 // Show an alert with error
115 window.alert('Error: '+err); 
116 }
117
118 }, '#paypal-button-container');
119
120 </script>
121</body>
122 
123