1d3 中文文档教程

发布于 3年前 浏览 22 项目主页 更新于 3年前

1D3 Javascript package

What is it?

该软件包将帮助您根据以下内容生成付款 URL 1D3 文档

How to use?

Get payment page URL

  1. Install the package (with your package manager):
npm install 1d3
yarn add 1d3
  1. Require somewhere in your code, set parameters and get the URL:
const { Payment } = require('1d3');

// create Payment object with your account ID and secret salt
const e = new Payment('112', 'my_secret');

// set payment details 
e.paymentAmount = 1000;
e.paymentId = 'FFCD12-30';
e.paymentCurrency = 'USD';

// set another parameters, like success or fail callback URL, customer details, etc.

// get payment URL
const url = e.getUrl();

现在您可以在结帐页面的某处呈现付款 url

Receive callback from 1D3

Express 示例:

const { Callback } = require('1d3');

app.post('/payment/callback', function(req, res) {
  const callback = new Callback('secret', req.body);
  if (callback.isPaymentSuccess()) {
    const paymentId = callback.getPaymentId();
    // here is your code for success payment
  }
});

请注意,如果签名无效,Callback 构造函数会抛出错误。

1D3 Javascript package

What is it?

It is package that will help you with generating payment URL according to 1D3 documentation.

How to use?

Get payment page URL

  1. Install the package (with your package manager):
npm install 1d3
yarn add 1d3
  1. Require somewhere in your code, set parameters and get the URL:
const { Payment } = require('1d3');

// create Payment object with your account ID and secret salt
const e = new Payment('112', 'my_secret');

// set payment details 
e.paymentAmount = 1000;
e.paymentId = 'FFCD12-30';
e.paymentCurrency = 'USD';

// set another parameters, like success or fail callback URL, customer details, etc.

// get payment URL
const url = e.getUrl();

Now your can render payment url somewhere on your checkout page.

Receive callback from 1D3

Example with Express:

const { Callback } = require('1d3');

app.post('/payment/callback', function(req, res) {
  const callback = new Callback('secret', req.body);
  if (callback.isPaymentSuccess()) {
    const paymentId = callback.getPaymentId();
    // here is your code for success payment
  }
});

Note that Callback constructor throws Error if signature isn't valid.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文