npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@a15-ghm/gh-payment

v1.0.0

Published

NPM package with gh-payment methods

Downloads

6

Readme

gh-payment

NPM package with payment methods

gh-payment is a package that includes different types of payment utility functions. Using gh-payment you can interact with different utilities for the processes of calculating, creating payment data and http requests to the TouchCR API.

Installation

  1. Install the gh-payment package by running this command
npm install --save @a15-ghm/gh-payment

Once gh-payment is installed, all packages in peerDependencies will also be installed (gh-utils and gh-models).

Usage

To use gh-payment, you need to set the environment variables. Import Environment from gh-utils package and pass BRAND and API_URL. It needs for setting headers to requests and making calls to the TouchCR API.

import Environment from '@a15-ghm/gh-utils/environment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  public ngOnInit() {
    Environment.setEnvVariables({ BRAND: 'brand', API_URL: 'api_url' });
  }
}

The above steps are basic usage instructions, below is a more detailed description of each part of the gh-payment package functionality

Coupon utils

.calculateCouponDiscount()

Claculates and returns the coupon discount depending on coupon info and subtotal

// The signature
function calculateCouponDiscount(
  cartOverValue: number,
  discountType: string,
  discountAmount: number,
  subtotal: number,
): number;

// Usage
import { calculateCouponDiscount } from '@a15-ghm/gh-payment/coupon';

const couponDiscount = calculateCouponDiscount(100, 'Discount %', 10, 299);

.getCouponInfo()

Makes a call to the TouchCR API to verify an existing coupon, then check the eligibility of the coupon - whether the coupon can be applied to products in the cart. Throws an error in case of any problems. If there are no errors and the coupon is eligible, it will return the coupon information from the TouchCR API.

// The signature
async function getCouponInfo(couponCode: string, productCartIds: string[]): Promise<ICouponResponse>;

// Usage
import { getCouponInfo } from '@a15-ghm/gh-payment/coupon';

const couponInfo = await getCouponInfo('Coupon_Code', ['01t0m000004HiNTAA0', '21F0m011104HiNTAA0']);

Shipping utils

.getShippingCost()

It is used to calculate shipping costs and it can return a default shipping cost of 0 if there are no variants in the cart, or it can return an international/domestic cost depending on the shipping country. If the shipping country is the United States or shipping is falsy, it can return 4.95 (domestic) or 0 (domestic free) depending on the incoming arguments freeShippingThreshold, isLoggedIn and cartSubtotal. FreeShippingThreshold is optional parameter, if you don't pass it, it will use 0

Example:

// The signature
function getShippingCost(
  country: string,
  cart: ICart,
  cartSubtotal: number,
  isLoggedIn: boolean,
  freeShippingThreshold = 0,
): ShippingCost;

// Usage
import { getShippingCost } from '@a15-ghm/gh-payment/shipping';

const shippingCost = getShippingCost('United States', { products: new Map(), variants: new Map() }, 100, true);

Tax utils

.getTax()

Creates a tax request body and makes a call to the TouchCR API to getting the tax. If the cart is empty, the shipping postal code is falsy, or the subtotal amount is 0, a default tax (0) will be returned. The shipping address incoming argument should contain the country and state in the form of a country code and state code

// The signature
async function getTax(
  shippingAddress: IAddress, // {  country: 'US', state: 'CA', city: 'City', street: 'Street 14', postal: '456123'}
  subtotal: number,
  cart: ICart,
  affiliateInfo: IAffiliateInfo,
  shippingCost: number,
  couponDiscount: number,
  cartCount: number,
): Promise<ITouchcrTax>;

// Usage
import { getTax } from '@a15-ghm/gh-payment/tax';

const tax: ITouchcrTax = await getTax(
  shippingAddress,
  subtotal,
  cart,
  affiliateInfo,
  shippingCost,
  couponDiscount,
  cartCount,
);

.getUpsellTax()

Creates a tax request body and makes a call to the TouchCR API for getting upsell tax. The shipping address incoming argument should contain the country and state in the form of a country code and state code.

// The signature
async function getUpsellTax(
  shippingAddress: IAddress, // {  country: 'US', state: 'CA', city: 'City', street: 'Street 14', postal: '456123'}
  affiliateInfo: IAffiliateInfo,
  upsell: IUpsell,
): Promise<ITouchcrTax>;

// Usage
import { getUpsellTax } from '@a15-ghm/gh-payment/tax';

const tax: ITouchcrTax = await getUpsellTax(shippingAddress, affiliateInfo, upsell);

.fetchTax()

Makes a call to the TouchCR API for getting tax. The account details in tax request body should contain the country and state in the form of a country code and state code.

// The signature
async function fetchTax(body: ITaxRequestBody): Promise<ITouchcrTax>;

// Usage
import { fetchTax } from '@a15-ghm/gh-payment/tax';

const tax: ITouchcrTax = await fetchTax(taxRequestBody);

Payment utils

.checkoutLoggedIn()

Makes a call to the TouchCR API for creation the payment for logged in user

// The signature
async function checkoutLoggedIn(paymentBody: IPaymentBody | IManualPaymentBody): Promise<ILoggedInPaymentResponse>;

// Usage
import { checkoutLoggedIn } from '@a15-ghm/gh-payment/payment';

const response = await checkoutLoggedIn(paymentBody);

.checkoutGuest()

Makes a call to the TouchCR API for creation the payment for not logged in user

// The signature
async function checkoutGuest(guestPaymentBody: IPaymentBody | IManualPaymentBody): Promise<IPaymentResponse>;

// Usage
import { checkoutGuest } from '@a15-ghm/gh-payment/payment';

const response = await checkoutGuest(guestPaymentBody);

.getManualCheckoutPaymentBody()

Returns a body for payment requests to the TouchCR API with credit card info

// The signature
async function getManualCheckoutPaymentBody(
  paymentDetails: IPaymentDetailsPaymentBody,
  cart: ICart,
  customerDetails: ICustomerDetails,
  creditCard: ICreditCardInfo,
  affiliateInfo: IAffiliateInfo,
  isGuest: boolean,
  sessionId: string | null,
  useSeparateBillingAddress = true,
): IManualPaymentBody;

// Usage
import { getManualCheckoutPaymentBody } from '@a15-ghm/gh-payment/payment';

const response = await getManualCheckoutPaymentBody(
  paymentDetails,
  cart,
  customerDetails,
  creditCard,
  affiliateInfo,
  isGuest,
  sessionId,
  useSeparateBillingAddress,
);

.getCheckoutPaymentBody()

Returns a body for payment requests to the TouchCR API

// The signature
async function getCheckoutPaymentBody(
  paymentDetails: IPaymentDetailsPaymentBody,
  cart: ICart,
  customerDetails: ICustomerDetails,
  affiliateInfo: IAffiliateInfo,
  sessionId: string,
  isGuest: boolean,
  useSeparateBillingAddress = true,
): IPaymentBody;

// Usage
import { getCheckoutPaymentBody } from '@a15-ghm/gh-payment/payment';

const response = await getCheckoutPaymentBody(
  paymentDetails,
  cart,
  customerDetails,
  affiliateInfo,
  sessionId,
  isGuest,
  (useSeparateBillingAddress = true),
);

PayPal utils

.getRedirectUrls()

Returns a object with redirect urls for PayPal. This object contains a url for canceling payment and a url for executing payment

// The signature
function getRedirectUrls(): IPayPalRedirectUrls;

// Usage
import { getRedirectUrls } from '@a15-ghm/gh-payment/paypal';

const redirectUrls = getRedirectUrls();

.initPayPalReq()

Creates a initial call to checkout an order and redirect to PayPal for auth

// The signature
async function initPayPalReq(paymentBody: IPaymentBody): Promise<IPayPalPaymentResponse>;

// Usage
import { initPayPalReq } from '@a15-ghm/gh-payment/paypal';

const response = await initPayPalReq(paymentBody);

.executePayPalReq()

Once we return from PayPal, we will have to actually execute the checkout

// The signature
async function executePayPalReq(
  orderDetails: IPaymentResponse,
  taxData: ITouchcrTax,
): Promise<IExecutePayPalPaymentResponse>;

// Usage
import { executePayPalReq } from '@a15-ghm/gh-payment/paypal';

const response = await executePayPalReq(orderDetails, taxData);

.initPayPalUpsellReq()

Creates a initial call to checkout an upsell order

// The signature
async function initPayPalUpsellReq(payPalUpsellPaymentBody: IPayPalUpsellPaymentBody): Promise<IPayPalPaymentResponse>;

// Usage
import { initPayPalUpsellReq } from '@a15-ghm/gh-payment/paypal';

const response = await initPayPalUpsellReq(payPalUpsellPaymentBody);