Logoelepay

JavaScript Quick Start

The elepay JavaScript SDK integrates elepay into web applications. This guide explains how to connect your web app with the elepay JavaScript SDK.

Supported versions

  • The elepay JavaScript SDK recommends the latest versions of Safari, Chrome, Edge, and Firefox (we guarantee operation on versions released within the last three years).
  • Development environment: Chrome is recommended.

Installation

The elepay JavaScript SDK is hosted at https://js.elepay.io/v1/ and is used by loading that domain.

<script src="https://js.elepay.io/v1/elepay.js"></script>

When using as a module, install the npm package elepay-js-sdk.

npm install --save elepay-js-sdk

Implementation

Initialize

var elepay = new Elepay('YOUR_PUBLISHABLE_KEY');

When installed via npm package

import { loadElepay } from 'elepay-js-sdk';

const elepay = await loadElepay('YOUR_PUBLISHABLE_KEY');

Elepay(publishableKey, options?)

ParameterTypeRequiredDescription
publishableKeystringtruePublishable key
optionsobjectfalseInitialization options
options.localestringfalse (default: auto)ja: Japanese, en: English, zh-CN: Simplified Chinese, zh-TW: Traditional Chinese, auto: detect from browser locale

Payment processing

After obtaining an elepay Charge object, call the following to process the payment.

elepay
  .handleCharge(chargeObject)
  .then(function (result) {
    // ① Normal flow
    if (result.type === 'cancel') {
      // Payment cancelled
    } else if (result.type === 'success') {
      // Payment succeeded
    }
  })
  .catch(function (err) {
    // ② Error handling
  });

For the methods below, the flow does not call the normal‑path handler (①) but instead redirects to the frontUrl in the charge extra data:

  • LinePay
  • Alipay
  • UnionPay
  • PayPay

elepay.handleCharge(chargeObject)

ParameterTypeRequiredDescription
chargeObjectobjecttrueCharge object created by the elepay server

Redirect to frontUrl

When redirecting, the following parameters are appended to frontUrl as query strings:

  • chargeId: Charge ID
  • orderNo: Order number
  • amount: Payment amount
  • currency: Currency code
  • status: Status (captured, failure, cancelled). For successful payments, captured is used.

Last updated on

On this page