基础理论 Google Pay JS
用于在Node.js环境中解密Google Pay Tokens的工具库.
特征
- 谷歌付费 支付方法 解密:使用易用接口安全地解密用户授权的Google Pay交易符.
- 密钥旋转:从不担心由于密钥旋转不可预测的行为导致的付款缺失. 只要在解密上下文中添加多键,并放心在旋转窗口时会同时解密出新和旧的令牌.
此软件包只支持 Google Pay
ECv2协议.
谷歌付费设置
遵循 Google Pay API 指南 用于您选择的平台(Web或Android)。 要使用此库, 您需要经过 PCI 一级认证并选择了符号化类型 DIRECT。 。 。 .
如果你没有PCI一级认证, 联系我们 学习如何使用
PAYMENT_GATEWAY符号化类型 .
安装
使用国家防范机制安装软件包:
npm install @basis-theory/google-pay-js --save
或者亚恩:
yarn add @basis-theory/google-pay-js
节点.js
下面的例子显示如何使用来自此寄存器的样本从文件系统将私钥加载到缓冲器中. 但你可以从你的KMS,秘密管理器,配置等设备中装入.
import { GooglePaymentTokenContext } from '@basis-theory/google-pay-js';
import fs from 'fs';
import token from './test/fixtures/ec/token.new.json';
// create the decryption context
const context = new GooglePaymentTokenContext({
// add as many merchant certificates you need
merchants: [
{
// optional certificate identifier
identifier: 'my-merchant-identifier',
// the private key is in PEM format
privateKeyPem: fs.readFileSync('./test/fixtures/key.new.pem'),
},
{
identifier: 'my-merchant-identifier',
// the private key is in PEM format
privateKeyPem: fs.readFileSync('./test/fixtures/key.old.pem'),
},
],
});
try {
// the paymentData you get back from loadPaymentData Promise/event
const token = JSON.parse(
paymentData.paymentMethodData.tokenizationData.token
);
// decrypts Google's PaymentMethodToken
console.log(context.decrypt(token));
} catch (error) {
// couldn't decrypt the token with given merchant keys
}
反应堆
此软件包可用于 反应堆 上下文。 以下例子说明如何解密Google Pay的代币并按规定为PAN提供保险.
const { Buffer } = require('buffer');
const { GooglePaymentTokenContext } = require('@basis-theory/google-pay-js');
const {
CustomHttpResponseError,
} = require('@basis-theory/basis-theory-reactor-formulas-sdk-js');
module.exports = async function (req) {
const {
bt,
args: {
// invoke the reactor passing the paymentData you get back from loadPaymentData Promise/event
paymentData: {
paymentMethodData: {
tokenizationData: { token: tokenString, ...tokenizationData },
...paymentMethodData
},
...paymentData
},
},
configuration: { PRIMARY_PRIVATE_KEY_PEM, SECONDARY_PRIVATE_KEY_PEM },
} = req;
// creates token context from keys configured in Reactor
const context = new GooglePaymentTokenContext({
merchants: [
{
privateKeyPem: Buffer.from(PRIMARY_PRIVATE_KEY_PEM),
},
{
privateKeyPem: Buffer.from(SECONDARY_PRIVATE_KEY_PEM),
},
],
});
try {
const token = JSON.parse(tokenString);
// decrypts Google's PaymentMethodToken
const {
paymentMethodDetails: { pan, expirationMonth, expirationYear },
} = context.decrypt(token);
// vaults PAN
const btToken = await bt.tokens.create({
type: 'card',
data: {
number: pan,
expiration_month: String(expirationMonth).padStart(2, '0'),
expiration_year: String(expirationYear),
},
});
// returns original details and vaulted token without sensitive PAN
return {
raw: {
btToken,
paymentData: {
paymentMethodData: {
tokenizationData,
...paymentMethodData,
},
...paymentData,
},
},
};
} catch (error) {
throw new CustomHttpResponseError({
status: 500,
body: {
message: error.message,
},
});
}
};