@auspayplus/open-payments-checkout

中文文档
1.8.0发布于 2024/06/12Apache-2.0TypeScriptESM + CJS近 30 天下载 3847

Common utilities, types and helpers for checkout

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录11 节
  1. Getting Started
  2. Basic Usage
  3. Javascript
  4. React
  5. Checkout params
  6. Further Info For Params
  7. Available Methods
  8. Callbacks and Errors
  9. Basic Merchant Package Flow
  10. Merchant Package Callbacks
  11. Possible Errors

Open Payments Checkout

A library/framework agnostic NPM package that provides a means to trigger the Open Payments Checkout process and other related utility functions.

Getting Started

Simply install the package by running one of the following:

  • For Yarn: yarn add @auspayplus/open-payments-checkout
  • For NPM: npm install @auspayplus/open-payments-checkout
  • For PNPM: pnpm install @auspayplus/open-payments-checkout

Basic Usage

Javascript

To instantiate Checkout in a JS environment, you can do the following:

import { Checkout } from '@auspayplus/open-payments-checkout';

const checkout = new Checkout({
  orderId: '123',
  url: 'https://{checkout_url}',
  clientId: 'client_id',
  onCheckoutClosed: () => {
    console.log('CHECKOUT COMPLETED!');
  },
});

And then bind the trigger to your event listener:

const openCheckout = () => checkout.open();
<button class="my-button" onclick=openCheckout()>My Button</button>

React

For React, the following is an example of how to instantiate the checkout.

import { Checkout } from '@auspayplus/open-payments-checkout';

export function MyComponent() {
  const checkout = new Checkout({
    orderId: '123',
    url: 'https://{checkout_url}',
    onCheckoutClosed: () => {
      console.log('CHECKOUT COMPLETED!');
    },
    onError: () => {
      console.log('AN ERROR OCCURRED!');
    },
    onPaymentSuccess: () => {
      console.log('PAYMENT IS SUCCESSFUL!');
    },
    onPaymentError: () => {
      console.log('PAYMENT HAS ERRORED!');
    },
    onTokensChanged: ({ accessToken, refreshToken }) => {
      console.log('TOKENS HAVE CHANGED!');
    },
  });

  const onClick = () => {
    checkout.open();
  };

  useEffect(() => {
    // This is required for the callbacks provided to work
    // otherwise, is negligible
    checkout.listenMessage();
  }, []);

  return <Button {...args} onClick={onClick} />;
}

Checkout params

There are a few arguments that you can pass in the Checkout class constructor to instantiate the checkout

ParamsDescriptionRequired
auth: objectAuth object that enables express checkout. This must be defined along with property mode defined as "express". More details in Further Info For ParamsOptional
orderId: stringAn order id is required to invoke the checkout process.Required
clientId?: stringThe client id is used to tag the wallet that is being used (e.g. Beem) as well as provide different experiences and functionality in the checkout journey. If a client id is not provided then the client id will be defaulted to Beem.Optional
mode?: stringThis property must be defined if attempting to use express checkout. Values can be of string "default" or "express"Optional
onCheckoutClosed({ error: Error, orderId: string })A callback that can be passed to be invoked upon closure of the checkout window.Optional
onError({ error: Error, orderId: string })A callback that can be passed to be invoked upon encountering errors in the checkout processOptional
onPaymentSuccess({ error: Error, orderId: string })A callback that can be passed to be invoked upon success during the payment process.Optional
onPaymentError({ error: Error, orderId: string })A callback that can be passed to be invoked upon error during the payment process.Optional
onTokensChanged({ accessToken, refreshToken })A callback that can be passed to be invoked when the access token and/or refresh token changes.Optional
windowFeaturesThis dictates how the window will be presented.Optional

Further Info For Params

auth

The auth property will allow for express checkout in the target checkout site. A mode with string value express must be declared along with this in order to enable this functionality.

PropertyValueRequired
access_tokenstringRequired
expires_innumberOptional
id_tokenstringOptional
refresh_tokenstringRequired
scopestringOptional
token_typestringOptional

You can pass this object to the auth property during the instantiation like so

const checkout = new Checkout({
  // Pass tokens into the auth property object
  auth: {
    access_token: '12345',
    refresh_token: '678910',
  },
  mode: 'express',
  orderId: '123',
  url: 'https://{checkout_url}',
});

onTokensChanged

The onTokensChanged callback will receive an object containing the new accessToken and refreshToken values when they change.

windowFeatures

The windowFeatures param is accepting an object which comprises the following:

PropertyValue
heightnumber
leftnumber
popup'yes' | 'no' | '1' | '0'
resizable'yes' | 'no' | '1' | '0'
topnumber
widthnumber

For example, if you want to customise the window features, you would instantiate Checkout like so:

const checkout = new Checkout({
  orderId: '123',
  url: 'https://{checkout_url}',
  windowFeatures: {
    width: 200,
    height: 200,
  },
});

Available Methods

Upon instantiation of the Checkout class, the following public methods/utilities will be made available

MethodDescription
isCheckoutOpen: booleanChecks if the checkout window is open or not
listenMessage(): voidRequired if utilising callbacks for the checkout
open(): voidOpens and instantiates the checkout window
close(): voidCloses the checkout window

Callbacks and Errors

Apart from kicking off the checkout process, the Merchant Package also facilitates communications between the merchant and the checkout. The merchant package accommodates this via 4 callback methods to which 3 are able to provide access to errors with 1 for any additional tasks a merchant may want to perform upon successful payment. Callbacks will use the following signatures for as arguments.

interface ICheckoutCallback {
  orderId: string;
  error?: Error;
}

The next section will provide a basic overview of the overall flow and followed by further details of these callbacks.

Basic Merchant Package Flow

Starting from the merchant’s site, the Merchant Package is instantiated, providing several methods for usage. One of these is the open method. The open method is then bound to a button, for example, the “Checkout with FlyPay” button, which would then instantiate the checkout flow. The merchant site must provide an orderId obtained from creating an order via the Beem As A Service (BaaS) API and provide this orderId when instantiating the Merchant Package.

At the start of the checkout process, the user authentication process is commences and the user is redirected to a PING login/signup flow. On completing the flow, a userToken is generated and passed to the checkout. The user is taken to the checkout landing page, which queries BaaS with the userToken and orderId to get the details of the user and the order. The user may then manage their cards (view, add, remove, update, set card as default), or simply hit the pay button to commence payment.

When the user hits the pay button, a series of requests are exchanged with BaaS, simplified here as the 'payment flow'. If all of these are successful, the user is taken to a 'payment success' screen, and the onPaymentSuccess() callback is triggered on the merchant site (note that this happens upon successful payment and does not wait until the checkout is closed).

Package Flow

Merchant Package Callbacks

The four merchant package callbacks are described here. Note that onPaymentSuccess does not provide access to errors. Only the orderId is accessible from there.

onCheckoutClosed({ error: Error, orderId: string })

onCheckoutClosed (previously onPaymentComplete) occurs at any time the checkout is closed without a payment succeeding or failing. If an error is present in the session at close, it will be accessible in the callback along with the orderId otherwise, only the orderId is accessible.

Payment complete

onError({ error: Error, orderId: string })

onError will only occur at instantiation if the orderId is not provided during the instantiation of the Merchant Package, or the orderId provided is expired.

Callback error

onPaymentError({ error: Error, orderId: string })

onPayment Error only occurs during the payment flow, allowing access to errors and the orderId within the callback function and any error handling in regards to payments.

Payment error

onPaymentSuccess({ orderId: string })

onPaymentSuccess is called when a payment flow has fully succeeded. Only the orderId is accessible from this callback. This callback also provides the means to perform additional work if required by the merchant.

Package callbacks

Possible Errors

Listed below are possible errors that can occur and which callback handles which. Note that, any errors occurring during the checkout process is detrimental to the success of a transaction and a user will no longer be able to complete the transaction if it occurs.

Error Details Friendly Message + UI example Actions
onError callback
Order ID Expired Caused at instantiation of checkout if an expired `orderId` is passed. Order id error Payment Loading Error
Don’t worry, your order is still there and you haven’t been charged yet. Please try closing the window and checking out again or contact Customer Service if this issue continues.
  • Display error message
  • Generate a new orderId and try again
Order ID Missing Caused at instantiation of checkout if no `orderId` is passed. ""
  • Pass an un-expired `orderId` and try again.
Instantiation Error Generic error if something goes wrong that isn’t covered above ""
  • Log error and investigate.
onPaymentError Callback
Generic Payment Error Generic error if something goes wrong during the payment process Generic error Payment Processing Error
We’re sorry, but there was an issue processing your payment. Don’t worry, you haven’t been charged yet. Please try again or contact Customer Service if this issue persists.
  • Log error and investigate.
onCheckoutClosed Callback
Authentication Error Caused if the user exits after a failed login/signup flow in Ping Errors handled by Ping
  • Log error and investigate.
  • Issue is either with user input or Ping service.
Card Management Error Caused by an error while trying to manage a card on BAAS Save card Save Card Error
We’re sorry, but there was an issue saving your card. Don’t worry, no changes have been made yet. Please try to save again or contact Customer Service if this issue persists.

Remove card Remove Card Error
We’re sorry, but there was an issue removing your card. Don’t worry, no changes have been made yet. Please try to remove again or contact Customer Service if this issue persists.
  • Log error.
Failed to get order details Caused by a failure to retrieve order details from BAAS Order details Payment Loading Error
Don’t worry, your order is still there and you haven’t been charged yet. Please try closing the window and checking out again or contact Customer Service if this issue continues.
  • Log error and investigate.
Failed to get user details Caused by a failure to get user information (primary concern for this is eg. a user’s payment methods) from BAAS User details Wallet Details Error
Sorry, there was a problem loading your wallet details. Your order is still here. Try going back and starting your checkout again or contact Customer Service for help.
  • Log error and investigate.
Generic Error Generic error if something goes wrong that isn’t covered by other errors Generic2 Payment Processing Error
We’re sorry, but there was an issue processing your payment. Don’t worry, you haven’t been charged yet. Please try again or contact Customer Service if this issue persists.
  • Log error and investigate.

版本与发布记录

@auspayplus/open-payments-checkout 共发布 22 个版本,首次发布于 2023/03/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.8.0latest2024/06/122 年前
1.7.62024/03/272 年前
1.7.52023/12/182 年前
1.7.42023/12/072 年前
1.7.32023/11/282 年前
1.7.22023/11/152 年前

关于 @auspayplus/open-payments-checkout 的常见问题

@auspayplus/open-payments-checkout 是什么?

Common utilities, types and helpers for checkout注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @auspayplus/open-payments-checkout?

在项目目录运行 npm install @auspayplus/open-payments-checkout,或使用 pnpm add / yarn add / bun add。

@auspayplus/open-payments-checkout 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@auspayplus/open-payments-checkout 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@auspayplus/open-payments-checkout 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@auspayplus/open-payments-checkout 可以商用吗?

@auspayplus/open-payments-checkout 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@auspayplus/open-payments-checkout 的下载量有多少?

根据 npm 官方下载统计,@auspayplus/open-payments-checkout 在 2026/10/07 – 2026/11/05 这 30 天内被下载 3,847 次,日均约 128 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@auspayplus/open-payments-checkout 还在维护吗?

最新版本 1.8.0 发布于 2024/06/12(2 年前);至今共发布 22 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/03/23。作者已将其标记为弃用,新项目建议寻找替代方案。