Skip to content

Instantly share code, notes, and snippets.

@Shaxadhere
Created October 5, 2022 22:57
Show Gist options
  • Save Shaxadhere/5907cca8c72be6d7a35795825224055c to your computer and use it in GitHub Desktop.
Save Shaxadhere/5907cca8c72be6d7a35795825224055c to your computer and use it in GitHub Desktop.
const { Checkout } = require('checkout-sdk-node')
require("dotenv").config()
const cko = new Checkout(process.env.CHECKOUT_SECRET_KEY, { pk: process.env.CHECKOUT_PUBLIC_KEY });
module.exports = makeAPayment = async (token, addressLine1, addressLine2, city, state, zip, amount, country="PK", phone, currency, paymentType, reference, description, customerEmail, customerName) => {
const countryCode = phone.slice(0,3)
const phoneNumber = phone.slice(3,-1)
const payment = await cko.payments.request({
source: {
token: token, // Generated by Checkout.Frames
billing_address: {
address_line1: addressLine1,
address_line2: addressLine2,
city: city,
state: state,
zip: zip,
country: country,
},
phone: {
country_code: countryCode,
number: phoneNumber,
},
},
currency: currency,
amount: amount*100,
payment_type: paymentType,
reference: reference,
description: description,
customer: {
email: customerEmail,
name: customerName,
},
metadata: {
value: 'none',
},
});
return payment
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment