-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper routes to create charge with token #61
Comments
Here is the miniapp code to do it 🙂 (thanks Julian) /**
* Charge
*/
univapay
.createTransactionToken(OnlineGateway.ALIPAY_ONLINE, username, metadata(authorizer, items), {
jwt,
secret
})
.then(({ id: transactionTokenId, storeId }) =>
univapay
.createCharge(
transactionTokenId,
amount(items),
{
...metadata(authorizer, items),
...(transaction?.title && {
internal_payments_transaction_name: transaction.title
})
},
{ jwt, secret }
)
.then(({ id, storeId }) => {...})
.catch(err =>
// otherwise there will be some latency before you can create another one for the app token
univapay
.deleteTransactionToken(storeId, transactionTokenId, { jwt, secret })
.then(() => Promise.reject(err))
)
/**
* Online
*/
univapay
.createTransactionToken(OnlineGateway.ALIPAY_ONLINE, username, metadata(authorizer, items), {
jwt,
secret
})
.then(({ id: transactionTokenId, storeId }) =>
univapay
.createCharge(
transactionTokenId,
amount(items),
{
...metadata(authorizer, items),
...(transaction?.title && {
internal_payments_transaction_name: transaction.title
})
},
{ jwt, secret }
)
.then(({ id, storeId }) =>
univapay.getIssuerToken(storeId, id, { jwt, secret }).then(
tap(() =>
lbb.addUnivaId(
items[0].detail_id,
items[0].store_id,
id,
null,
username,
token,
{
host,
app: APP
}
)
)
)
)
.then(({ issuerToken, callMethod }) => ({
statusCode: 200,
body: { order, items, charge: { issuerToken, callMethod } }
}))
.catch(err =>
// otherwise there will be some latency before you can create another one for the app token
univapay
.deleteTransactionToken(storeId, transactionTokenId, { jwt, secret })
.then(() => Promise.reject(err))
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We are currently repeating the charge creation process boilerplate:
The idea here is to create some helper function to handle the whole process for it instead of having everyone repeating the same creation flow.
We may as well add a function for the other kind of payment if needed at some point.
The text was updated successfully, but these errors were encountered: