https://developer.paypal.com/docs/checkout/standard/customize/display-funding-source/
var FUNDING_SOURCES = [paypal.FUNDING.CREDIT, paypal.FUNDING.CARD, paypal.FUNDING.VENMO];
FUNDING_SOURCES.forEach(function (fundingSource){
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: "{{$UserData->User_Email}}",
// phone: {
// phone_type: "MOBILE",
// phone_number: {
// national_number: ""
// }
// }
},
// shipping_type: 'PICKUP',
application_context: { shipping_preference: 'NO_SHIPPING' },
purchase_units: [{
amount: {
currency_code: "USD",
value: '{{$T_Price}}',
breakdown: {
item_total: {
/* Required when including the `items` array */
currency_code: "USD",
value: '{{$T_Price}}'
}
}
},
items: [
{
name: '{{$Plan}}',
unit_amount: {
currency_code: 'USD',
value: '{{$Price}}'
},
quantity: 1,
},
{
name: 'Gateway charges & Tax Fees:',
unit_amount: {
currency_code: 'USD',
value: '{{$fee}}'
},
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 = "{{$Invoice_ID}}";
let Amount = details.purchase_units[0].amount.value; // amount
// let email_address = details.purchase_units[0].payee.email_address; // Paypal business email address
let email_address = details.payer.email_address; //payer email address
// 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));
let fast_name = details.payer.name.given_name;
let last_name = details.payer.name.surname;
let full_name = fast_name + " " +last_name;
let address1 = "address_line_1";
let admin_area_2 = "address_line_2";
let postal_code = "postal_code";
let Payment_Type = "Paypal";
let Pay_Plan = "{{$Plan}}";
let Pay_Price = "{{$Price}}";
let Pay_fee = "{{$fee}}";
let Pay_Days = "{{$Days}}";
let Plan_ID = "{{$Plan_ID}}";
// console.log(JSON.stringify(details.payer.name.given_name + " | " + details.payer.name.surname));
if(status =='COMPLETED'){
var URL = "/InvoicepaypalpayCOMPLETED";
axios.post(URL, {status:status,payer_id:payer_id,details_id:details_id,InvoiceID:InvoiceID,
Amount:Amount,email_address:email_address,full_name:full_name,Payment_Type:Payment_Type,
Pay_Plan:Pay_Plan,Pay_Price:Pay_Price,Pay_fee:Pay_fee,Pay_Days:Pay_Days,Plan_ID:Plan_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')
window.location.href = "/Dashboard";
//window.location.reload();
}
}).catch(function(error) {
alert('ERROR')
// $('#DialogIconedDanger').modal('show');
})
}else{
alert(status)
}
});
},
fundingSource: fundingSource,
}).render('#paypal-button-container');
})
------------------------------
Video Link:
https://www.youtube.com/watch?v=9IxBHgQ1S4k
https://drive.google.com/file/d/1X2ulBYbd3dBpA2D4YjBQvnV7VKDP2wAM/view?usp=share_link
Post a Comment