Files
EMI-Backend/Payments.js
Adolfo Reyna 364f38a28d payments v1
2021-11-10 22:03:49 -08:00

42 lines
1.3 KiB
JavaScript

const Stripe = require('stripe');
const stripe = Stripe(process.env.STRIPE);
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;
}
}