1.3.5 • Published 1 year ago

@trustasia/js-sdk v1.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

TrustAsia - Node.js/JavaScript

Install

npm

$ npm install @trustasia/js-sdk

yarn

$ yarn add @trustasia/js-sdk

Example

import { FinanceClient, FinanceDoRenew, Session } from "@trustasia/js-sdk";
const express = require("express");

const app = express();
app.use(express.json());
const port = 3000;

const session = new Session(
  {
    accessKey: "test_mch",
    secretKey: "bff149a0b87f5b0e00d9dd364e9ddaa0",
  },
  false
);
const client = new FinanceClient(session, "http://localhost:9000");

app.get("/subscribe", async (_req, res) => {
  const subReq = {
    user_id: "test_js_user",
    nickname: "test_js_nickname",
    product_id: "test_product_code_subscribe",
  };
  try {
    const resp = await client.CreateSubscribe(subReq);
    res.send(resp);
  } catch (error) {
    res.send(error.response.data);
  }
});

app.post("/callback", (req, res) => {
  try {
    const data = client.FinanceCallback(req);

    // parse content
    const content = JSON.parse(Buffer.from(data.content, "base64").toString());
    switch (data.do) {
      case FinanceDoRenew:
        // TODO handle
        console.log(content);
        res.status(200).send("success");
        break;
      default:
        res.send("unsupported action");
        break;
    }
  } catch (error) {
    res.status(400).send(`${error}`);
  }
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});
1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.9

1 year ago

1.1.4

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.0

2 years ago