PayPal api example refactoring
This commit is contained in:
@ -267,28 +267,30 @@ exports.getTwitter = function(req, res, next) {
|
||||
|
||||
exports.getPayPal = function(req, res, next) {
|
||||
paypal.configure(secrets.paypal);
|
||||
var payment_details = {
|
||||
'intent': 'sale',
|
||||
'payer': {
|
||||
'payment_method': 'paypal'
|
||||
|
||||
var paymentDetails = {
|
||||
intent: 'sale',
|
||||
payer: {
|
||||
payment_method: 'paypal'
|
||||
},
|
||||
'redirect_urls': {
|
||||
'return_url': secrets.paypal.returnUrl,
|
||||
'cancel_url': secrets.paypal.cancelUrl
|
||||
redirect_urls: {
|
||||
return_url: secrets.paypal.returnUrl,
|
||||
cancel_url: secrets.paypal.cancelUrl
|
||||
},
|
||||
'transactions': [
|
||||
transactions: [
|
||||
{
|
||||
'description': 'Node.js Boilerplate',
|
||||
'amount': {
|
||||
'currency': 'USD',
|
||||
'total': '2.99'
|
||||
description: 'Node.js Boilerplate',
|
||||
amount: {
|
||||
currency: 'USD',
|
||||
total: '2.99'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
paypal.payment.create(payment_details, function(err, payment) {
|
||||
|
||||
paypal.payment.create(paymentDetails, function(err, payment) {
|
||||
if (err) return next(err);
|
||||
req.session.payment_id = payment.id;
|
||||
req.session.paymentId = payment.id;
|
||||
var links = payment.links;
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
if (links[i].rel === 'approval_url') {
|
||||
@ -306,10 +308,10 @@ exports.getPayPal = function(req, res, next) {
|
||||
*/
|
||||
|
||||
exports.getPayPalSuccess = function(req, res, next) {
|
||||
var payment_id = req.session.payment_id;
|
||||
var payment_details = { 'payer_id': req.query.PayerID };
|
||||
paypal.payment.execute(payment_id, payment_details, function(error, payment) {
|
||||
if (error) {
|
||||
var paymentId = req.session.paymentId;
|
||||
var paymentDetails = { 'payer_id': req.query.PayerID };
|
||||
paypal.payment.execute(paymentId, paymentDetails, function(err, payment) {
|
||||
if (err) {
|
||||
res.render('api/paypal', {
|
||||
result: true,
|
||||
success: false
|
||||
|
@ -3,7 +3,7 @@ extends ../layout
|
||||
block content
|
||||
.page-header
|
||||
h2
|
||||
i.fa.fa-dollar(style='color: #1B4A7D')
|
||||
i.fa.fa-dollar
|
||||
| PayPal API
|
||||
|
||||
.btn-group.btn-group-justified
|
||||
@ -17,19 +17,15 @@ block content
|
||||
i.fa.fa-gear
|
||||
| API Playground
|
||||
|
||||
h3
|
||||
img(src='/img/paypal.png', width=50, height=50)
|
||||
span Sample Payment
|
||||
|
||||
if result
|
||||
if canceled
|
||||
h3 Payment got canceled!
|
||||
if success
|
||||
h3 Payment got executed successfully!
|
||||
a(href='/api/paypal')
|
||||
button.btn.btn-primary New payment
|
||||
else
|
||||
div
|
||||
p Redirects to PayPal and allows authorizing the sample payment.
|
||||
a(href=approval_url)
|
||||
button.btn.btn-primary Authorize payment
|
||||
if result
|
||||
if canceled
|
||||
h3 Payment got canceled!
|
||||
if success
|
||||
h3 Payment got executed successfully!
|
||||
a(href='/api/paypal')
|
||||
button.btn.btn-primary New payment
|
||||
else
|
||||
p.lead Redirects to PayPal and allows authorizing the sample payment.
|
||||
a(href=approval_url)
|
||||
button.btn.btn-primary Authorize payment
|
Reference in New Issue
Block a user