payments v1

This commit is contained in:
Adolfo Reyna
2021-11-10 21:59:01 -08:00
parent 687be41e3e
commit a2b462abb7
4 changed files with 112 additions and 43 deletions
+39 -41
View File
@@ -1,44 +1,42 @@
const Stripe = require('stripe');
const stripe = Stripe(process.env.STRIPE);
const addNewCustomer = async (email, profile) => {
const customer = await Stripe.customers.create({
email,
description: profile ? profile.firstName + " " + profile.lastName : "new costumer",
});
return customer;
}
const getCustomerByID = async (id) => {
const customer = await Stripe.customers.retrieve(id);
return customer;
}
const addNewCustomerCard = async (customer, cardInfo) => {
let template = {
"address_city": cardInfo.address_city,
"address_country": cardInfo.address_country,
"address_line1": cardInfo.address_line1,
"address_line2": cardInfo.address_line2,
"address_state": cardInfo.address_state,
"address_zip": cardInfo.address_zip,
customer,
"exp_month": cardInfo.exp_month,
"exp_year": cardInfo.exp_year,
"name": cardInfo.name,
};
const card = await stripe.customers.createSource(
'cus_KKsGI28Nrbm61K',
template
);
return card;
}
const getCustomerCard = async (customer, card) => {
const card = await stripe.customers.retrieveSource(
customer,
card
);
return card;
}
module.exports = {
async addNewCustomer(email, profile){
const customer = await Stripe.customers.create({
email,
description: profile ? profile.firstName + " " + profile.lastName : "new costumer",
});
return customer;
},
async getCustomerByID(id){
const customer = await Stripe.customers.retrieve(id);
return customer;
},
async addNewCustomerCard(customer, cardInfo){
let template = {
"address_city": cardInfo.address_city,
"address_country": cardInfo.address_country,
"address_line1": cardInfo.address_line1,
"address_line2": cardInfo.address_line2,
"address_state": cardInfo.address_state,
"address_zip": cardInfo.address_zip,
customer,
"exp_month": cardInfo.exp_month,
"exp_year": cardInfo.exp_year,
"name": cardInfo.name,
};
const card = await stripe.customers.createSource(
customer,
template
);
return card;
},
async getCustomerCard(customer, cardId){
const card = await stripe.customers.retrieveSource(
customer,
cardId
);
return card;
}
}