<script src="https://www.paypal.com/sdk/js?client-id=XXXXX"> </script>
<div style="text-align: center;" id="paypal-button-container"></div>
<script type="text/javascript">
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
payer: {
name: {
given_name: "{{$UserData->User_FastName}}",
surname: "{{$UserData->User_LastName}}"
},
address: {
address_line_1: '{{$UserData->User_Address}}',
address_line_2: '',
admin_area_2: '{{$UserData->User_City}}',
admin_area_1: '{{$UserData->User_State}}',
postal_code: '{{$UserData->User_ZipCode}}',
country_code: 'US'
},
email_address: "{{$UserData->User_Email}}",
phone: {
phone_type: "MOBILE",
phone_number: {
national_number: "{{$UserData->UserPhone}}"
}
}
},
purchase_units: [{
description: "Add Point",
amount: {
value: "{{$UserDeposetAmount}}"
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
{{--let payer_id = details.payer.payer_id;--}}
{{--let details_id = details.id;--}}
{{--let status = details.status;--}}
{{--// let amount = details.payments.captures.amount.value;--}}
{{--let myAMOUNT = "{{$UserDeposetAmount}}";--}}
// let payer_id = details.transactionId;
// transaction.status + ': ' + transaction.id
// alert(payer_id)
console.log(JSON.stringify(details));
// if(status =='COMPLETED'){
// var URL = "/paypalAddBalance";
// axios.post(URL, { status: status, payer_id: payer_id, details_id: details_id, myAMOUNT: myAMOUNT,
// }).then(function(response) {
// if (response.status !== 200 || response.data == 0) {
// $('#DialogIconedDanger').modal('show');
// }else if(response.status == 200 && response.data == 1) {
// // alert('Pay Successful')
// $('#DialogIconedSuccess').modal('show');
// }
// }).catch(function(error) {
// // alert('ERROR')
// $('#DialogIconedDanger').modal('show');
// })
//
// }else{
// alert(status)
// }
});
}
}).render('#paypal-button-container');
------------------------console.logPayPal api https://developer.paypal.com/sdk/js/reference/ https://developer.paypal.com/sdk/js/configuration/ { "id": "0FG110414D3092103", "intent": "CAPTURE", "status": "COMPLETED", "purchase_units": [{ "reference_id": "default", "amount": { "currency_code": "USD", "value": "3.00" }, "payee": { "email_address": "sb-xhgkf14173793@business.example.com", "merchant_id": "FGYAPYA9SQY7W" }, "description": "Add Point", "soft_descriptor": "PAYPAL *TEST STORE TES", "shipping": { "name": { "full_name": "RAJ TELECOM TELECOM" }, "address": { "address_line_1": "4143 Cleveland Ave Apt B", "admin_area_2": "San Diego", "admin_area_1": "CA", "postal_code": "92103", "country_code": "US" } }, "payments": { "captures": [{ "id": "18180855FH7008319", "status": "COMPLETED", "amount": { "currency_code": "USD", "value": "3.00" }, "final_capture": true, "disbursement_mode": "INSTANT", "seller_protection": { "status": "ELIGIBLE", "dispute_categories": ["ITEM_NOT_RECEIVED", "UNAUTHORIZED_TRANSACTION"] }, "create_time": "2022-03-10T06:32:59Z", "update_time": "2022-03-10T06:32:59Z" }] } }], "payer": { "name": { "given_name": "RAJ", "surname": "TELECOM" }, "email_address": "wewewewewewewe@gmail.com", "payer_id": "BVN3JYZE5EFJU", "address": { "country_code": "US" } }, "create_time": "2022-03-10T06:32:44Z", "update_time": "2022-03-10T06:32:59Z", "links": [{ "href": "https://api.sandbox.paypal.com/v2/checkout/orders/0FG110414D3092103", "rel": "self", "method": "GET" }] }
</script>
----------------------------------------------------
New
https://stackoverflow.com/questions/68756981/how-to-show-multiple-items-on-paypal
https://www.paypal-community.com/t5/REST-APIs/PayPal-Checkout-javascript-with-Smart-Payment-Buttons-create/td-p/1824785
<script type="text/javascript">
paypal.Buttons({
createOrder: function(data, actions) {
// Set up the transaction
return actions.order.create({
payer: {
name: {
given_name: "",
surname: ""
},
address: {
address_line_1: '',
address_line_2: '',
admin_area_2: '',
admin_area_1: '',
postal_code: '',
country_code: 'US'
},
// email_address: "",
// phone: {
// phone_type: "MOBILE",
// phone_number: {
// national_number: ""
// }
// }
},
{{--purchase_units: [{--}}
{{-- description: "{{$InvoiceData->Items_1_Name}}",--}}
{{-- description: "{{$InvoiceData->Items_1_Name}}",--}}
{{-- amount: {--}}
{{-- value: '{{$GrandTotal}}'--}}
{{-- }--}}
{{--}]--}}
purchase_units: [{
amount: {
currency_code: "USD",
value: '{{$GrandTotal}}',
breakdown: {
item_total: {
/* Required when including the `items` array */
currency_code: "USD",
value: '{{$GrandTotal}}'
}
}
},
items: [{
name: 'Test item 1',
unit_amount: {
currency_code: 'USD',
value: '{{$Items_1_Price}}'
},
quantity: 1,
description: 'Uaua item 1 description'
}, {
name: 'Test item 2',
unit_amount: {
currency_code: 'USD',
value: '{{$Items_2_Price}}'
},
quantity: 1,
description: 'Test item 2 description'
},{
name: 'Test item 3',
unit_amount: {
currency_code: 'USD',
value: '{{$Items_3_Price}}'
},
quantity: 1,
description: 'Test item 3 description'
},{
name: 'Test item 4',
unit_amount: {
currency_code: 'USD',
value: '{{$Items_4_Price}}'
},
quantity: 1,
description: 'Test item 4 description'
},{
name: 'Tex Fee:',
unit_amount: {
currency_code: 'USD',
value: '{{$Invoice_Tax_Fees}}'
},
quantity: 1,
}]
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
let payer_id = details.payer.payer_id;
// let details_id = details.id;
let status = details.status;
// let amount = details.payments.captures.amount.value;
let details_id = details.purchase_units[0].payments.captures[0].id;
//
{{--let InvoiceID = "{{$InvoiceData->InvoiceID}}";--}}
{{--let VATFees = {{$Invoice_Tax_Fees}};--}}
{{--let Amount = {{$SubTotal}};--}}
{{--let AmountAndVAT = {{$GrandTotal}};--}}
let Amount = details.purchase_units[0].amount.value; // amount
let email_address = details.purchase_units[0].payee.email_address; // full_name
let full_name = details.purchase_units[0].shipping.name.full_name; // full_name
let address1 = details.purchase_units[0].shipping.address.address_line_1; // address_line_1
let admin_area_2 = details.purchase_units[0].shipping.address.admin_area_2; // address_line_2
let postal_code = details.purchase_units[0].shipping.address.postal_code; // postal_code
// let country_code = details.purchase_units[0].shipping.address.country_code; // country_code
// console.log(JSON.stringify(details));
if(status =='COMPLETED'){
var URL = "/paypalpay";
axios.post(URL, {status:status,payer_id:payer_id,details_id:details_id
}).then(function(response) {
if (response.status !== 200 || response.data == 0) {
alert('Pay ERROR')
// $('#DialogIconedDanger').modal('show');
}else if(response.status == 200 && response.data == 1) {
// window.location.assign("/viptips")
$('#exampleModal').modal('hide');
// alert('Pay Successful')
}
}).catch(function(error) {
alert('ERROR')
// $('#DialogIconedDanger').modal('show');
})
}else{
alert(status)
}
});
}
}).render('#paypal-button-container');
</script>
Post a Comment