61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
const GraphQLClient = require("graphql-request").GraphQLClient;
|
|
const path = require("path");
|
|
const queries = require("../graphql-client/queries");
|
|
const Dinero = require("dinero.js");
|
|
|
|
require("dotenv").config({
|
|
path: path.resolve(
|
|
process.cwd(),
|
|
`.env.${process.env.NODE_ENV || "development"}`
|
|
),
|
|
});
|
|
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
|
|
|
|
exports.payment = async (req, res) => {
|
|
const { amount, stripe_acct_id } = req.body;
|
|
console.log("exports.payment -> amount", amount);
|
|
console.log("exports.payment -> stripe_acct_id", stripe_acct_id);
|
|
try {
|
|
|
|
const pr = await stripe.paymentRequest.create({
|
|
country: "CA",
|
|
currency: "cad",
|
|
total: {
|
|
label: "Demo total",
|
|
amount: 1099,
|
|
},
|
|
requestPayerName: true,
|
|
requestPayerEmail: true,
|
|
});
|
|
|
|
console.log(pr);
|
|
|
|
await stripe.paymentIntents
|
|
.create(
|
|
{
|
|
payment_method_types: ["card"],
|
|
amount: amount,
|
|
currency: "cad",
|
|
application_fee_amount: 100,
|
|
},
|
|
{
|
|
stripeAccount: stripe_acct_id,
|
|
}
|
|
)
|
|
.then(function (paymentIntent) {
|
|
try {
|
|
return res.send({
|
|
clientSecret: paymentIntent.client_secret,
|
|
});
|
|
} catch (err) {
|
|
return res.status(500).send({
|
|
error: err.message,
|
|
});
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.log("error", error);
|
|
res.status(400).send(error);
|
|
}
|
|
};
|