UNPKG

commerce-vuex

Version:
42 lines (35 loc) 1.76 kB
import { auth, nav } from 'oak-vuex' //const { getHubAuthHeader } = auth const { wrapRequest } = nav //const hubName = process.env.VUE_APP_RETAINHUB_NAME import { JSONToURLEncoded } from './common.service' const stripeAPIUrl = process.env.VUE_APP_STRIPE_API_URL const stripeSecretKey = process.env.VUE_APP_STRIPE_SECRET_KEY const doFetchPaymentMethodList = wrapRequest(({ stripeCustomerId }) => { const requestOptions = { method: 'GET', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Authorization': 'Bearer ' + stripeSecretKey } }; return fetch(`${stripeAPIUrl}/v1/customers/${stripeCustomerId}/payment_methods?type=card`, requestOptions); }) const doPostPaymentMethod = wrapRequest(({ type, card, billingDetails }) => { let formBody = JSONToURLEncoded({ type: type, card, billing_details: billingDetails }); const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Authorization': 'Bearer ' + stripeSecretKey }, body: formBody }; return fetch(`${stripeAPIUrl}/v1/payment_methods`, requestOptions); }) const doAttachPaymentMethodToCustomer = wrapRequest(({ paymentMethodId, stripeCustomerId }) => { let formBody = JSONToURLEncoded({ customer: stripeCustomerId }); const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Authorization': 'Bearer ' + stripeSecretKey }, body: formBody }; return fetch(`${stripeAPIUrl}/v1/payment_methods/${paymentMethodId}/attach`, requestOptions); }) export default { doFetchPaymentMethodList, doPostPaymentMethod, doAttachPaymentMethodToCustomer }