feat(M08-A): 接入充值微信支付调起
This commit is contained in:
@@ -10,6 +10,8 @@ const token = signAccessToken({
|
||||
|
||||
let createdInput;
|
||||
let listInput;
|
||||
let prepayInput;
|
||||
let notifyInput;
|
||||
const app = await buildApp({
|
||||
recharge: {
|
||||
jwtSecret: secret,
|
||||
@@ -61,6 +63,23 @@ const app = await buildApp({
|
||||
giftAmountCents: 2000,
|
||||
idempotent: false
|
||||
};
|
||||
},
|
||||
async createWechatPrepay(input) {
|
||||
prepayInput = input;
|
||||
return {
|
||||
rechargeOrderId: input.rechargeOrderId,
|
||||
rechargeNo: 'RCHTEST',
|
||||
amountCents: 10000,
|
||||
timeStamp: '1782360000',
|
||||
nonceStr: 'nonce',
|
||||
package: 'prepay_id=wx-recharge-prepay',
|
||||
signType: 'RSA',
|
||||
paySign: 'signed'
|
||||
};
|
||||
},
|
||||
async processWechatNotification(headers, rawBody, traceId) {
|
||||
notifyInput = { headers, rawBody, traceId };
|
||||
return { rechargeOrderId: '901', status: 'CREDITED', idempotent: false };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +110,33 @@ assert.equal(createdInput.userId, '21');
|
||||
assert.equal(createdInput.planId, '31');
|
||||
assert.equal(createdInput.traceId, 'm08a-recharge-order');
|
||||
|
||||
const prepay = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/app-api/recharge/orders/901/wechat-prepay',
|
||||
headers: { authorization: `Bearer ${token}` }
|
||||
});
|
||||
assert.equal(prepay.statusCode, 200);
|
||||
assert.equal(prepayInput.tenantId, '7');
|
||||
assert.equal(prepayInput.platformAppId, '9');
|
||||
assert.equal(prepayInput.userId, '21');
|
||||
assert.equal(prepay.json().data.package, 'prepay_id=wx-recharge-prepay');
|
||||
|
||||
const notify = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/app-api/recharge/wechat/notify',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'wechatpay-timestamp': '1782360001',
|
||||
'wechatpay-nonce': 'notify-nonce',
|
||||
'wechatpay-serial': 'PLATFORM-SERIAL',
|
||||
'wechatpay-signature': 'signature'
|
||||
},
|
||||
payload: '{"resource":"encrypted"}'
|
||||
});
|
||||
assert.equal(notify.statusCode, 200);
|
||||
assert.equal(notifyInput.headers.serial, 'PLATFORM-SERIAL');
|
||||
assert.equal(notifyInput.rawBody, '{"resource":"encrypted"}');
|
||||
|
||||
const invalid = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/app-api/recharge/orders',
|
||||
|
||||
Reference in New Issue
Block a user