Chuyển tới nội dung chính

showPaymentMethod

showPaymentMethod là API dùng hiển thị màn hình chọn phương thức thanh toán

Tham số

Thuộc tínhKiểu dữ liệuBắt buộcMô tả
paymentApiKeyStringPayment api key tương ứng với điểm thanh toán
amountnumberGiá trị đơn hàng.
allowedCardPrefixesstring[]Danh sách prefix BIN (6 chữ số) để filter danh sách thẻ hiển thị trong UI (VD: chỉ hiển thị thẻ có prefix nằm trong list). Nếu không truyền thì hiển thị theo default của hệ thống.
successFunctionCallback function sau khi user chọn xong phương thức thanh toán.
failFunctionCallback function trong trường hợp user không chọn phương thức thanh toán, argument sẽ là errorMessage
completeFunctionCallback function khi việc chọn phương thức thanh toán kết thúc cho dù thành công hay thất bại.

Success callback

Response là object phương thức thanh toán đã được user chọn với kiểu dữ liệu như sau:

Thuộc tínhKiểu dữ liệu
categorystring
codestring
typestring
iconUrlstring
namestring
providerIdstring
providerNamestring
paymentMethodIdstring
userPaymentMethodIdstring

Fail callback

Fail callback payload là string và sẽ là error message

Ví dụ

import apis from '@v-miniapp/apis'

apis.showPaymentMethod({
paymentApiKey: "xxx",
amount: 100000,
allowedCardPrefixes: ["970436", "970418", "411111"], // optional
success: (res) => {
// tạo đơn hàng, gọi initPayment để thực hiện thanh toán
apis.initPayment({
orderInfo: {
amount: 100000,
currency: "VND",
description: "Payment for order #123456",
orderId: "Order Id 001",
referenceId: "Reference_123456",
orderInfo: {
customerName: "Nguyen Van A",
customerEmail: "[email protected]",
customerPhone: "+84901234567",
orderCreatedAt: 1640995200000,
items: [
{
name: "Product A",
sku: "Sku 001",
quantity: 2,
unitPrice: 50000,
description: "High quality product",
},
],
},
secureHash: "string",
},
success: (res) => {
apis.alert({ title: "payment", content: res });
},
});
},
});