0.4.1 • Published 2 years ago

ericrajaonarison-alma-client v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@permettezmoideconstruire/alma-client

build status code style libraries status

See Documentation

Install

yarn add @permettezmoideconstruire/alma-client

Usage

import type { AxiosResponse } from 'axios'

import {
  getClient,
  createPayment,
  AlmaPaymentOrderPayload,
  AlmaPayment
} from '@permettezmoideconstruire/alma-client'

// This creates and configure
// dedicated Axios instance for Alma
const almaClient = getClient(
  process.env.ALMA_API_KEY,
  // Optional but typically useful to switch to sandbox API endpoint
  process.env.ALMA_API_ENDPOINT
)

// API types helpers for payloads
const paymentOrderPayload: AlmaPaymentOrderPayload = {
  payment: {
    billing_address: {
      country: 'France'
    },
    purchase_amount: 150000
  }
}

// Each call is curryfied : method(almaClient)(data / options)
const result: AxiosResponse<Payment> = await createPayment(almaClient)(paymentOrderCreation)

// API types for returns
const payment: Payment = result.data