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ính | Kiểu dữ liệu | Bắt buộc | Mô tả |
|---|---|---|---|
| paymentApiKey | String | ✅ | Payment api key tương ứng với điểm thanh toán |
| amount | number | ❌ | Giá trị đơn hàng. |
| allowedCardPrefixes | string[] | ❌ | 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. |
| success | Function | ❌ | Callback function sau khi user chọn xong phương thức thanh toán. |
| fail | Function | ❌ | Callback function trong trường hợp user không chọn phương thức thanh toán, argument sẽ là errorMessage |
| complete | Function | ❌ | Callback 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ính | Kiểu dữ liệu |
|---|---|
| category | string |
| code | string |
| type | string |
| iconUrl | string |
| name | string |
| providerId | string |
| providerName | string |
| paymentMethodId | string |
| userPaymentMethodId | string |
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 });
},
});
},
});