用于 JavaScript 的 Astropay SDK
AstroPay SDK用于方便产品集成
目录
开始
先决条件
- 节点.js v14 或更高.
安装
使用您最喜欢的软件包管理器安装 @astropay/astropay-sdk 软件包.
国家预防机制数字 :
npm install --save @astropay/astropay-sdk
亚伦:
yarn add @astropay/astropay-sdk
使用量
平台输入
SDK 配置参数
要正确配置 SDK,init 方法需要接收带有以下属性的APP ID和配置对象:
| 财产 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 环境 | 'sandbox' | 'production' | undefined | 'production' | 报恩取用. |
| 语言 | 支持的语言 未定义 | 'en' | Init 对象上设置的语言优先于该对象上的 URL 属性语言 ASTROPAY_RESPONSE |
| 日志 | Logger 实例 undefined | undefined | 在 SDK 内使用控制台日志动作 |
如果在init上没有设置语言属性, SDK 将尝试在 URL 上使用语言查询参数 ASTROPAY_RESPONSE。如果两者没有设定,则SDK将使用默认语言: english
代码片段 :
import AstropaySDK, { ClientConfiguration, ConsoleLogger, DepositStatus } from '@astropay/astropay-sdk';
// SDK Config
const config: ClientConfiguration = {
environment: 'production',
language: 'en',
logger: new ConsoleLogger(),
};
// SDK Init
AstroPaySDK.init(APP_ID, config);
活动听众
设置事件收听器, 接收回调 funcion 作为参数 .
// SDK Event Listeners
const eventListening = AstroPaySDK.getEventListener('deposit');
eventListening.on('close', (data) => {
console.log('data on close event', data);
}
);
方法调用
方法参数
当调用其中一种产品方法(Deposit QQ Cashout QQ Onboarding)以有效打开SDK时,被注意的参数是: ASTROPAY_RESPONSE 编辑 configUI 属性来根据您的需要操纵 UI :
| 财产 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 阿斯托佩克语NAME | 对象 | 不适用: 强制发送呼叫 | 您拨打时由 AstroPay 服务提供的输入对象 。 请检查access-date=中的日期值 (帮助) Usage 一节的示例. |
| 财产 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 背景情况 | 'static' | 'active' | 'static' | 如果你想要的话 AstroPay SDK 软件 当用户点击 Backdrop( 内容外部) 时关闭 active 若为 static,背景元素不会在用户点击外部内容时关闭 SDK 模式. |
| zindex 数据 | 字符串 | 'auto' | Z-index属性指定弹出物的堆栈顺序. 更大的堆栈顺序总是在下堆栈顺序的元素前. |
注意到
ASTROPAY_RESPONSE应配置产品调用的真实值(Disposit QQ Cashout QQ上载)。 注意不要就这些属性发送错误的值
交存
// Non mandatory object
const configUI = {backdrop:'active', zIndex:'auto'}
// Mandatory object
const ASTROPAY_RESPONSE = {
"merchant_deposit_id": "0c435984-0b55-4f16-a15e-36070fbcee19",
"deposit_external_id": "QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"status": "PENDING",
"url": "https://onetouch-sandbox.astropay.com/deposit/QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"type": "default"
};
// Show the DEPOSIT client
AstropaySDK.deposit(ASTROPAY_RESPONSE);
现金流出
const ASTROPAY_RESPONSE = {
"merchant_cashout_id": "0c435984-0b55-4f16-a15e-36070fbcee19",
"cashout_external_id": "QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"status": "PENDING",
"url": "https://onetouch-sandbox.astropay.com/cashout/QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe"
};
// Show the CASHOUT client
AstropaySDK.cashout(ASTROPAY_RESPONSE);
上岗
const ASTROPAY_RESPONSE = {
"platform_merchant_id": "0c435984-0b55-4f16-a15e-36070fbcee19",
"merchant_name": "Merchant"
"onboarding_external_id": "QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"status": "PENDING",
"url": "https://onetouch-sandbox.astropay.com/onboarding/QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
};
// Show the ONBOARDING client
AstropaySDK.onboarding(ASTROPAY_RESPONSE);
付款
这种方法收到 AstroPay 响应, 并返回一个承诺, 它将解析一个对象的支付数据, 并随您的意愿在您的网站上显示 .
//Method Response
AstropaySDK.payment(AstropayResponse): Promise<PaymentData>
方法响应接口
interface PaymentData {
amount: number;
currency: string;
status: string;
payment_type: string;
data: {
txt_qr: string;
image: string;
} & Record<string, any>
}
返回的对象字段 :
- 数额: 付款数额
- 货币: 支付货币
- 缴款情况
- 支付 类型: 使用此支付所选方法定义的字符串
- 数据:带有密钥-值格式的付款数据对象
通知此方法仅与类型相容:"出道"存款
重要
根据支付 类型字段,数据对象可包括特定字段:
| 付款类型 | 数据 | 数值 | 说明 |
|---|---|---|---|
| 临九 | 对象 | txt qr: 字符串, (中文(简体) ), 图像:字符串 | Pix 付款作为字符串的 qr 代码 . 包含 qr 代码图像的 Base64 字符串 |
// Mandatory object
const ASTROPAY_RESPONSE = {
"merchant_deposit_id": "0c435984-0b55-4f16-a15e-36070fbcee19",
"deposit_external_id": "QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"status": "PENDING",
"url": "https://onetouch-sandbox.astropay.com/deposit/QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"type": "gateway"
};
// Get the payment data response
AstropaySDK.payment(ASTROPAY_RESPONSE).
.then(result => {
//This is the payment data response object
console.log(result)
})
示例答复:
{
amount: 5,
currency: "BRL",
status: "PENDING",
payment_type: "PIX",
data: {
txt_qr: "examplePixCode"
image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAYAAAAY4QDjAAAABmJLR0QA/wD/AP+gvaeTAAADfElEQVRoge2aXW/TQBBFf2BOwAhoh0CaQt0EfQAdAEYAIUARgCFWJED7FhYgFiwKFCAEsEKA"
}
}
签名
这种方法允许您在您的站点上实现“ Astropay 签名” 按钮 .
在站点上,您想要显示选项设置带有"ap-login" id的元素.
//On your site
<div id="ap-login"></div>
// Mandatory Parameters
client_id: string
redirect_uri: string
// Show the Sign in with AstroPay button
AstropaySDK.signin(client_id, redirect_uri);
支持的语言
| 语言 | 代码 |
|---|---|
| 联合国 | 内 |
| 西班牙语Name | 对 |
| 印度尼西亚 | 编号 |
| 日本人 | 对 |
| 한국의 | 小可,别这样 |
| 葡萄牙 | ưμ㼯a |
| ไทย | 编号 |
| 蒂尔克 | 双 |
| 蒂扬·维斯特 | vi. 请检查url=值 (帮助) |
| 簡中 | 日语 |
提升
V4 - 最新数据
SDK的最后一个版本提供了更好的UI控制,事件收听器,新的配置参数和新的产品集成使用.
为了充分了解这个版本,请检查使用部分的文件.
中断更改
要正确配置自动 SDK 模式关闭和重定向的事件, 请检查关于此文档的新事件收听器部分 .
五.3
中断更改
请注意,对于旧版本 _external_id 启动SDK UI是必要的。 现在,该方法接收了由您自己的服务提供的AstroPay init响应的对象.
- 遗产法调用 :
const ASTROPAY_EXTERNAL_DEPOSIT_ID = 'External Deposit ID';
AstropaySDK.showDeposit(ASTROPAY_EXTERNAL_DEPOSIT_ID);
- V3 更新方法呼叫 :
const ASTROPAY_RESPONSE = {
"merchant_deposit_id": "0c435984-0b55-4f16-a15e-36070fbcee19",
"deposit_external_id": "QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"status": "PENDING",
"url": "https://onetouch-sandbox.astropay.com/deposit/QYPvyLz9fM57EGHtR1DV3TcZOlBng7Uw1m1KWUpe",
"type": "default"
};
// Show the DEPOSIT client
AstropaySDK.deposit(ASTROPAY_RESPONSE);
五. 2级
用法实例
//Your APP ID SDK Credential
const APP_ID = "";
const ASTROPAY_CONFIG = {
environment: "production",
onDepositStatusChange: (depositResult) => getDepositStatus(depositResult), //Subscribes to every transaction status update.
onClose: (depositResult) => iframeClosed(depositResult),
};
//Initiates the SDK with the configuration set above
AstropaySDK.init(APP_ID, ASTROPAY_CONFIG);
//Sets the Deposit External ID generated for the deposit
const ASTROPAY_EXTERNAL_DEPOSIT_ID = "oehpJvCma8jaoaM7qmK3m3MX1LsmUWk8iulDl3Wx";
//Here you can do something according to the transaction current status.
const getDepositStatus = (depositResult) => { console.log(depositResult);};
const iframeClosed = (depositResult) => {
//Here you can also do a action if the user closes the iFrame, also checking the transaction status.
console.log(
"action: iFrame was closed",
"Deposit Status:",
depositResult
);
};
支助
我们提供详细文件,说明 AstroPay OneTouch API 指南。请检查它是否有开发者可能需要的更多信息.
如果你需要更多的技术支持,请 联系支持
许可证
版权:"2023 AstroPay". 版权所有.