Gathering detailed insights and metrics for wma-bridge
Gathering detailed insights and metrics for wma-bridge
Gathering detailed insights and metrics for wma-bridge
Gathering detailed insights and metrics for wma-bridge
npm install wma-bridge
Typescript
Module System
Node Version
NPM Version
70.4
Supply Chain
98.2
Quality
78.8
Maintenance
100
Vulnerability
100
License
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
This is a JavaScript library designed to facilitate seamless communication between mini-applications and mobile applications. It provides structured methods to handle authorization codes, user consent data, and trade payment data with callback functions for success and failure scenarios.
To use JS bridge, refer to the following steps:
1<head> 2 <script src="https://cdn.jsdelivr.net/gh/Buddhima-JD3/wma-bridge@master/index.js" type="module"></script> 3</head>
or
Run the following code in the root directory of the mini program project:
1npm install wma-bridge --save
For more information about NPM, refer to NPM Package Management.
To use JS bridge in plain html, you need to import the file index.js
from wma-bridge
.
Sample code
1<!DOCTYPE html> 2<html> 3 <head> 4 <script src="https://cdn.jsdelivr.net/gh/Buddhima-JD3/wma-bridge@master/index.js" type="module"></script> 5 </head> 6 <body> 7 <button id="getAuthCodeBtn">Get Auth Code</button> 8 9 <script type="module"> 10 document.addEventListener('DOMContentLoaded', function () { 11 if (window.my && typeof my.initiate === 'function') { 12 my.initiate({ 13 'AuthCode': { 14 success: function (data) { 15 console.log('AuthCode received:', data); 16 document.dispatchEvent(new CustomEvent('authCodeSuccess', { detail: data })); 17 }, 18 fail: function (err) { 19 console.error('Auth Code Sync Error:', err); 20 document.dispatchEvent(new CustomEvent('authCodeFailure', { detail: err })); 21 } 22 }, 23 }); 24 } 25 26 document.getElementById('getAuthCodeBtn').addEventListener('click', function () { 27 if (window.my && typeof my.getAuthCode === 'function') { 28 const data = { 29 clientId: 'clientId', 30 redirectUrl: 'redirectUrl' 31 }; 32 my.getAuthCode(data); 33 } 34 }); 35 36 }); 37 </script> 38</body> 39</html>
or
To use JS bridge in native mini programs, you need to import the wma-bridge
package on the mini program page. Then you can call the JSAPIs exported by the package. To learn more, check the sample code below.
Sample code
1import { my, syncAuthCode } from 'wma-bridge' 2 3ngOnInit(): void { 4 5 my.initiate({ 6 [syncAuthCode]: { 7 success: (res) => this.customMethod(res), 8 fail: (err) => console.error('Custom Error Message', err), 9 }, 10 }); 11 12 const data = { 13 clientId: 'clientId', 14 redirectUrl: 'redirectUrl' 15 }; 16 my.getAuthCode(JSON.stringify(data), { 17 success: function (res) { 18 console.log('Success:', res); 19 }, 20 fail: function (err) { 21 console.error('Fail:', err); 22 }, 23 }); 24 } 25
Use this API to request the authorization code.
1import { my } from 'wma-bridge' 2 3 const data = { 4 clientId: 'clientId', 5 redirectUrl: 'redirectUrl' 6 }; 7 8 my.getAuthCode(data, { 9 success: function (res) { 10 console.log('Success:', res); 11 }, 12 fail: function (err) { 13 console.error('Fail:', err); 14 }, 15 });
Property | Type | Required | Description |
---|---|---|---|
clientId | String | Y | ClientId Which is Generated from Server When On-boarding Process |
redirectUrl | String | Y | Redirect URL of the Merchant Which is Used in On-boarding Process |
Use this API to synchronize the authorization code via this callback. Use the OpenAPI endpoints to exhange the code to a token.
1import { my, syncAuthCode } from 'wma-bridge' 2 3 my.initiate({ 4 [syncAuthCode]: { 5 success: (res) => this.customMethod(res), 6 fail: (err) => console.error('Custom Error Message', err), 7 }, 8 });
Property | Type | Required | Description |
---|---|---|---|
code | String | Y | Authorization Code |
Use this API to initiate the payment flow via this callback.
1import { my } from 'wma-bridge' 2 3 const data = { 4 data.orderId = 'orderId'; 5 data.currencyCode = 'currencyCode'; 6 data.amount = 'amount', 7 data.token = 'token'; 8 }; 9 10 my.getTradePay(data, { 11 success: function (res) { 12 console.log('Success:', res); 13 }, 14 fail: function (err) { 15 console.error('Fail:', err); 16 } 17 });
Property | Type | Required | Description |
---|---|---|---|
orderId | String | Y | Merchant Generated OrderId |
currencyCode | String | N | Currency Code |
amount | String | Y | Total Transaction Amount |
token | String | Y | The Token Which is Granted from Authorization Server |
Use this API to synchronize payment response details via this callback.
1import { my, syncTradePayData } from 'wma-bridge' 2 3 my.initiate({ 4 [syncTradePayData]: { 5 success: (res) => this.customMethod(res), 6 fail: (err) => console.error('Custom Error Message', err), 7 }, 8 });
Property | Type | Required | Description |
---|---|---|---|
auxNo | String | Y | Transaction Reference Number |
MIT
No vulnerabilities found.
No security vulnerabilities found.