I'm integrating the Stripe checkout in my web app. I've implemented Stripe checkout on the angular front end and have also created a backend that is supposed to receive the token passed by stripe checkout. Upon submission of the stripe checkout form, my POST http request is not passing data to the backend. Although I get a 200 status from Stripe, I get no response for my nodejs.
I'm also getting this error but I do not think it pertains to the front end backend connection.
Refused to frame js.stripe.com/:2 'stripe url' frame because it violates the following Content Security Policy directive: "frame-src 'self' stripecheckout: bitcoin:
Here is my checkout method invoked by a form.
openCheckout() {
let total = (this.donation * 100);
let handler = (<any>window).StripeCheckout.configure({
key: 'key_test',
locale: 'auto',
token: (token: any) => {
const transaction = new Charge(total, token.id);
console.log('From navbar nonObject ' + token.id + ' ' + total);
console.log(transaction + ' From navbar');
this.keyService.charge(transaction);
}
});
handler.open({
name: 'Delaware March for Jesus',
description: 'Donation',
amount: total
});
this.donation = 0;
this.donationEmail = '';
}
Here is my Service code that implements the charge and passes the token to the backend.
charge(transaction) {
const body = JSON.stringify(transaction);
const headers = new Headers();
headers.append('Content-type', 'application/json');
return this.http.post(this.keysUrlDev + '/charge', body, { headers: headers })
.map((response: Response) => response.json())
.catch((error: Response) => Observable.throw(error.json()));
}
A simple angular model I constructed for transactions.
export class Charge {
constructor(public amount: number,
public token: string) {}
}
And my POST route on nodejs that takes the token and passes it through the stripe library charge.create method.
router.post('/charge', function(req, res, next) {
var amount = req.body.amount;
var token = req.body.token;
stripe.charges.create({
amount: amount,
currency: 'usd',
description: 'Delaware March For Jesus Donation',
source: token
}, function(err, charge) {
if (err) {
console.log(req.body.amount + ' From POST' + req.body.token);
return res.status(500).json({
title: 'An error occured',
error: err
});
}
res.status(201).json({
message: 'Charged successfully',
obj: charge
});
});
});
via Jonathan Corrin
No comments:
Post a Comment