0.0.192 • Published 4 months ago

@mypay-tw/payment v0.0.192

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

消費者在特店進行購買商品的當下,特店向系統發動申請請求,撰寫方式請參考 typescript 範例。

付費請求的流程圖

npm.io

生命週期

npm.io

特店網站發動初始化請求

初始化流完成後即可顯示支付工具畫面,並且可以進行付款,開發上建議畫面載入當下就直接進行初始化動作,載入完畢前可事先將root的元素先做隱藏,等到消費者按下付款按鈕再將root元素顯示出來。

// 初始化範例
import paymentBuilder from '@mypay-tw/payment';
import type { Payment } from '@mypay-tw/payment';

const token = '特店或經銷商的 InAppPaymentToken';
const storeUid = 'pfn與store_id 被 AES-256 金鑰加密後的密文';
const layer = '特店使用 "store", 經銷商使用 "agent"';
const root = '請輸入您將要顯示支付工具畫面的元素的selector';

paymentBuilder({
  token,
  storeUid,
  layer,
  root,
  clientUrl: location.href,
  language: 'zh-TW',
})
.setWhenTradeStartLifeCycle(tradeStart)
.setWhenGotTradeTokenLifeCycle(sendTradeToken)
.setWhenGoToFinishPageLifeCycle(goToFinishPage)
.setWhenTradeFinishLifeCycle(tradeFinish)
.setWhenGotErrorLifeCycle(whenGotError)
.build()
.then((response) => {
  console.log('payment init done.', response.getAllPayment());
  // 取得
  payment.value = response;
  console.timeEnd('create payment instance');
});


// 得到交易序號透過後端進行交易
function sendTradeToken(token: string, responseCallback: (code: string) => void) {
  console.timeEnd('trade start');
  console.log(token);
  fetch('電商後端發送交易的API位置!', {
    method: 'POST',
    body: JSON.stringify({ tradeToken: token })
  }).then((response) => {
    return response.json();
  }).then((result) => {
    console.log(result);
    responseCallback(result.response.code as string);
    console.time('trade finish');
  }).catch((err) => {
    console.log(err);
    responseCallback('error');
    console.time('trade finish');
  });
}
  • 初始化所需參數
欄位型態說明
tokenstring特店或經銷商的 InAppPaymentToken
storeUidstringpfn與store_id 被 AES-256 金鑰加密後的密文
layerstring特店使用 "store", 經銷商使用 "agent"
rootstring顯示支付工具畫面的元素,為 html tag 的 id
  • 初始化包含註冊以下觸發事件
事件名稱對應方法
當消費者點擊送出交易setWhenTradeStartLifeCycle
當取得交易序號setWhenGotTradeTokenLifeCycle
當交易畫面到達結果頁面上setWhenGoToFinishPageLifeCycle
當交易結束setWhenTradeFinishLifeCycle
當交易發生錯誤setWhenGotErrorLifeCycle
0.0.192

4 months ago

0.0.191

4 months ago

0.0.190

4 months ago

0.0.169

4 months ago

0.0.164

4 months ago

0.0.163

4 months ago

0.0.162

4 months ago

0.0.161

4 months ago

0.0.168

4 months ago

0.0.167

4 months ago

0.0.166

4 months ago

0.0.165

4 months ago

0.0.160

4 months ago

0.0.175

4 months ago

0.0.174

4 months ago

0.0.173

4 months ago

0.0.172

4 months ago

0.0.179

4 months ago

0.0.178

4 months ago

0.0.177

4 months ago

0.0.176

4 months ago

0.0.171

4 months ago

0.0.170

4 months ago

0.0.186

4 months ago

0.0.185

4 months ago

0.0.184

4 months ago

0.0.183

4 months ago

0.0.189

4 months ago

0.0.188

4 months ago

0.0.187

4 months ago

0.0.182

4 months ago

0.0.181

4 months ago

0.0.180

4 months ago

0.0.159

4 months ago

0.0.158

4 months ago

0.0.153

4 months ago

0.0.157

4 months ago

0.0.156

4 months ago

0.0.155

4 months ago

0.0.154

4 months ago

0.0.152

4 months ago

0.0.151

4 months ago

0.0.150

4 months ago

0.0.149

5 months ago

0.0.148

5 months ago

0.0.147

5 months ago

0.0.146

5 months ago

0.0.145

6 months ago

0.0.144

6 months ago

0.0.143

6 months ago

0.0.142

6 months ago

0.0.141

6 months ago

0.0.140

6 months ago

0.0.139

6 months ago

0.0.138

6 months ago

0.0.137

6 months ago

0.0.136

6 months ago

0.0.135

6 months ago

0.0.134

6 months ago

0.0.133

6 months ago

0.0.132

6 months ago

0.0.131

6 months ago

0.0.130

6 months ago

0.0.129

6 months ago

0.0.128

6 months ago

0.0.127

6 months ago

0.0.126

6 months ago

0.0.125

6 months ago

0.0.124

6 months ago

0.0.123

6 months ago

0.0.122

6 months ago

0.0.121

6 months ago

0.0.120

6 months ago

0.0.119

6 months ago

0.0.118

6 months ago

0.0.117

6 months ago

0.0.116

6 months ago

0.0.115

6 months ago

0.0.114

6 months ago

0.0.113

6 months ago

0.0.112

6 months ago

0.0.111

6 months ago

0.0.110

6 months ago

0.0.109

6 months ago

0.0.108

6 months ago

0.0.107

6 months ago

0.0.106

7 months ago

0.0.105

7 months ago

0.0.104

7 months ago

0.0.103

7 months ago

0.0.102

7 months ago