{"_id":"@a15-ghm/gh-payment","_rev":"2-15cb5d21180fb0030f5e50dbbe5a8ba4","name":"@a15-ghm/gh-payment","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@a15-ghm/gh-payment","version":"1.0.0","description":"NPM package with gh-payment methods","main":"./index.js","scripts":{"check":"npm run prettier:fix && npm run lint:fix && npm run test","test":"jest","compile":"rm -rf dist && rollup -c --bundleConfigAsCjs","transfromImports":"tsc-alias","packageScriptsPreparation":"cp package.json dist && cp README.md dist && cd dist && npm pkg delete scripts.prepare","build":"npm run compile && npm run transfromImports && npm run packageScriptsPreparation","lint":"eslint .","lint:fix":"npm run lint -- --fix .","prettier":"prettier --check './**'","prettier:fix":"npm run prettier -- --write","publishPackage":"npm run build && cd dist && npm publish --access public","npmPack":"npm run build && cd dist && npm pack"},"peerDependencies":{"@a15-ghm/gh-models":"^4.2.0","@a15-ghm/gh-utils":"^4.4.0"},"devDependencies":{"@jest/globals":"^29.5.0","@types/jest":"^29.5.3","@types/node":"^20.1.4","@typescript-eslint/parser":"^6.1.0","babel-jest":"^29.5.0","eslint":"^8.45.0","eslint-config-airbnb-typescript":"^17.0.0","eslint-config-prettier":"^8.8.0","eslint-import-resolver-typescript":"^3.5.5","eslint-plugin-import":"^2.27.5","eslint-plugin-prettier":"^5.0.0","fs-extra":"^11.2.0","husky":"^8.0.3","jest":"^29.6.1","prettier":"^3.0.0","rollup":"^4.7.0","rollup-plugin-typescript2":"^0.36.0","ts-jest":"^29.1.0","ts-node":"^10.9.2","tsc-alias":"^1.8.6","typescript":"^5.2.0"},"_id":"@a15-ghm/gh-payment@1.0.0","gitHead":"0c38d80ca587c1f47e2445d53592007364dd0725","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-njUdgZSynbDoJIyrN0WqHpnqtw5S5/qCdR2vk9H9p9N/dI5zJSvt3NuU8umw3AMbdR19xWI511aefbZ2TSTybA==","shasum":"7a7997ed3f4d794ac91d542b5b30710b0bc68745","tarball":"https://registry.npmjs.org/@a15-ghm/gh-payment/-/gh-payment-1.0.0.tgz","fileCount":36,"unpackedSize":35966,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGgTYK8DOLRMJwMPv3Jvup4XAmOJkax/ZKXUdWZ7H1x5AiAmtz5+0KKgR6w12qdjnl/0OoW/+XQrRM8Cx62cdRXvkg=="}]},"_npmUser":{"name":"devops-ghm-npm","email":"dev@goldenhippo.com"},"directories":{},"maintainers":[{"name":"devops-ghm-npm","email":"dev@goldenhippo.com"},{"name":"danni.liu","email":"danni.liu@goldenhippo.com"},{"name":"s.bely","email":"s.bely@itransition.com"},{"name":"kiskina_victoria","email":"v.kiskina@itransition.com"},{"name":"sergey.kuzovlev","email":"s.kuzovlev@itransition.com"},{"name":"s.bozhik","email":"s.bozhik@itransition.com"},{"name":"brian.park","email":"brian@goldenhippo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gh-payment_1.0.0_1703841676225_0.14363225542266767"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-29T09:21:16.143Z","1.0.0":"2023-12-29T09:21:16.414Z","modified":"2024-05-21T15:51:40.771Z"},"maintainers":[{"email":"dev@goldenhippo.com","name":"devops-ghm-npm"},{"email":"danni.liu@goldenhippo.com","name":"danni.liu"},{"email":"v.kiskina@itransition.com","name":"kiskina_victoria"},{"email":"s.kuzovlev@itransition.com","name":"sergey.kuzovlev"},{"email":"brian@goldenhippo.com","name":"brian.park"}],"description":"NPM package with gh-payment methods","readme":"# gh-payment\n\nNPM package with payment methods\n\n`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.\n\n# Installation\n\n1. Install the `gh-payment` package by running this command\n\n```bash\nnpm install --save @a15-ghm/gh-payment\n```\n\nOnce `gh-payment` is installed, all packages in peerDependencies will also be installed (`gh-utils` and `gh-models`).\n\n## Usage\n\nTo 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.\n\n```ts\nimport Environment from '@a15-ghm/gh-utils/environment';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent implements OnInit {\n  public ngOnInit() {\n    Environment.setEnvVariables({ BRAND: 'brand', API_URL: 'api_url' });\n  }\n}\n```\n\nThe above steps are basic usage instructions, below is a more detailed description of each part of the gh-payment package functionality\n\n## Coupon utils\n\n### [.calculateCouponDiscount()](src/utils/coupon/coupon.ts)\n\nClaculates and returns the coupon discount depending on coupon info and subtotal\n\n```ts\n// The signature\nfunction calculateCouponDiscount(\n  cartOverValue: number,\n  discountType: string,\n  discountAmount: number,\n  subtotal: number,\n): number;\n\n// Usage\nimport { calculateCouponDiscount } from '@a15-ghm/gh-payment/coupon';\n\nconst couponDiscount = calculateCouponDiscount(100, 'Discount %', 10, 299);\n```\n\n### [.getCouponInfo()](src/utils/coupon/coupon.ts)\n\nMakes 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.\n\n```ts\n// The signature\nasync function getCouponInfo(couponCode: string, productCartIds: string[]): Promise<ICouponResponse>;\n\n// Usage\nimport { getCouponInfo } from '@a15-ghm/gh-payment/coupon';\n\nconst couponInfo = await getCouponInfo('Coupon_Code', ['01t0m000004HiNTAA0', '21F0m011104HiNTAA0']);\n```\n\n## Shipping utils\n\n### [.getShippingCost()](src/utils/shipping/shipping.ts)\n\nIt 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.\nFreeShippingThreshold is optional parameter, if you don't pass it, it will use 0\n\nExample:\n\n```ts\n// The signature\nfunction getShippingCost(\n  country: string,\n  cart: ICart,\n  cartSubtotal: number,\n  isLoggedIn: boolean,\n  freeShippingThreshold = 0,\n): ShippingCost;\n\n// Usage\nimport { getShippingCost } from '@a15-ghm/gh-payment/shipping';\n\nconst shippingCost = getShippingCost('United States', { products: new Map(), variants: new Map() }, 100, true);\n```\n\n## Tax utils\n\n### [.getTax()](src/utils/tax/tax.ts)\n\nCreates 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\n\n```ts\n// The signature\nasync function getTax(\n  shippingAddress: IAddress, // {  country: 'US', state: 'CA', city: 'City', street: 'Street 14', postal: '456123'}\n  subtotal: number,\n  cart: ICart,\n  affiliateInfo: IAffiliateInfo,\n  shippingCost: number,\n  couponDiscount: number,\n  cartCount: number,\n): Promise<ITouchcrTax>;\n\n// Usage\nimport { getTax } from '@a15-ghm/gh-payment/tax';\n\nconst tax: ITouchcrTax = await getTax(\n  shippingAddress,\n  subtotal,\n  cart,\n  affiliateInfo,\n  shippingCost,\n  couponDiscount,\n  cartCount,\n);\n```\n\n### [.getUpsellTax()](src/utils/tax/tax.ts)\n\nCreates 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.\n\n```ts\n// The signature\nasync function getUpsellTax(\n  shippingAddress: IAddress, // {  country: 'US', state: 'CA', city: 'City', street: 'Street 14', postal: '456123'}\n  affiliateInfo: IAffiliateInfo,\n  upsell: IUpsell,\n): Promise<ITouchcrTax>;\n\n// Usage\nimport { getUpsellTax } from '@a15-ghm/gh-payment/tax';\n\nconst tax: ITouchcrTax = await getUpsellTax(shippingAddress, affiliateInfo, upsell);\n```\n\n### [.fetchTax()](src/utils/tax/tax.ts)\n\nMakes 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.\n\n```ts\n// The signature\nasync function fetchTax(body: ITaxRequestBody): Promise<ITouchcrTax>;\n\n// Usage\nimport { fetchTax } from '@a15-ghm/gh-payment/tax';\n\nconst tax: ITouchcrTax = await fetchTax(taxRequestBody);\n```\n\n## Payment utils\n\n### [.checkoutLoggedIn()](src/utils/payment/payment.ts)\n\nMakes a call to the TouchCR API for creation the payment for logged in user\n\n```ts\n// The signature\nasync function checkoutLoggedIn(paymentBody: IPaymentBody | IManualPaymentBody): Promise<ILoggedInPaymentResponse>;\n\n// Usage\nimport { checkoutLoggedIn } from '@a15-ghm/gh-payment/payment';\n\nconst response = await checkoutLoggedIn(paymentBody);\n```\n\n### [.checkoutGuest()](src/utils/payment/payment.ts)\n\nMakes a call to the TouchCR API for creation the payment for not logged in user\n\n```ts\n// The signature\nasync function checkoutGuest(guestPaymentBody: IPaymentBody | IManualPaymentBody): Promise<IPaymentResponse>;\n\n// Usage\nimport { checkoutGuest } from '@a15-ghm/gh-payment/payment';\n\nconst response = await checkoutGuest(guestPaymentBody);\n```\n\n### [.getManualCheckoutPaymentBody()](src/utils/payment/payment.ts)\n\nReturns a body for payment requests to the TouchCR API with credit card info\n\n```ts\n// The signature\nasync function getManualCheckoutPaymentBody(\n  paymentDetails: IPaymentDetailsPaymentBody,\n  cart: ICart,\n  customerDetails: ICustomerDetails,\n  creditCard: ICreditCardInfo,\n  affiliateInfo: IAffiliateInfo,\n  isGuest: boolean,\n  sessionId: string | null,\n  useSeparateBillingAddress = true,\n): IManualPaymentBody;\n\n// Usage\nimport { getManualCheckoutPaymentBody } from '@a15-ghm/gh-payment/payment';\n\nconst response = await getManualCheckoutPaymentBody(\n  paymentDetails,\n  cart,\n  customerDetails,\n  creditCard,\n  affiliateInfo,\n  isGuest,\n  sessionId,\n  useSeparateBillingAddress,\n);\n```\n\n### [.getCheckoutPaymentBody()](src/utils/payment/payment.ts)\n\nReturns a body for payment requests to the TouchCR API\n\n```ts\n// The signature\nasync function getCheckoutPaymentBody(\n  paymentDetails: IPaymentDetailsPaymentBody,\n  cart: ICart,\n  customerDetails: ICustomerDetails,\n  affiliateInfo: IAffiliateInfo,\n  sessionId: string,\n  isGuest: boolean,\n  useSeparateBillingAddress = true,\n): IPaymentBody;\n\n// Usage\nimport { getCheckoutPaymentBody } from '@a15-ghm/gh-payment/payment';\n\nconst response = await getCheckoutPaymentBody(\n  paymentDetails,\n  cart,\n  customerDetails,\n  affiliateInfo,\n  sessionId,\n  isGuest,\n  (useSeparateBillingAddress = true),\n);\n```\n\n## PayPal utils\n\n### [.getRedirectUrls()](src/utils/paypal/paypal.ts)\n\nReturns a object with redirect urls for PayPal. This object contains a url for canceling payment and a url for executing payment\n\n```ts\n// The signature\nfunction getRedirectUrls(): IPayPalRedirectUrls;\n\n// Usage\nimport { getRedirectUrls } from '@a15-ghm/gh-payment/paypal';\n\nconst redirectUrls = getRedirectUrls();\n```\n\n### [.initPayPalReq()](src/utils/paypal/paypal.ts)\n\nCreates a initial call to checkout an order and redirect to PayPal for auth\n\n```ts\n// The signature\nasync function initPayPalReq(paymentBody: IPaymentBody): Promise<IPayPalPaymentResponse>;\n\n// Usage\nimport { initPayPalReq } from '@a15-ghm/gh-payment/paypal';\n\nconst response = await initPayPalReq(paymentBody);\n```\n\n### [.executePayPalReq()](src/utils/paypal/paypal.ts)\n\nOnce we return from PayPal, we will have to actually execute the checkout\n\n```ts\n// The signature\nasync function executePayPalReq(\n  orderDetails: IPaymentResponse,\n  taxData: ITouchcrTax,\n): Promise<IExecutePayPalPaymentResponse>;\n\n// Usage\nimport { executePayPalReq } from '@a15-ghm/gh-payment/paypal';\n\nconst response = await executePayPalReq(orderDetails, taxData);\n```\n\n### [.initPayPalUpsellReq()](src/utils/paypal/paypal.ts)\n\nCreates a initial call to checkout an upsell order\n\n```ts\n// The signature\nasync function initPayPalUpsellReq(payPalUpsellPaymentBody: IPayPalUpsellPaymentBody): Promise<IPayPalPaymentResponse>;\n\n// Usage\nimport { initPayPalUpsellReq } from '@a15-ghm/gh-payment/paypal';\n\nconst response = await initPayPalUpsellReq(payPalUpsellPaymentBody);\n```\n","readmeFilename":"README.md"}