getPrepay(data: GetPrepayParams)

Requires:
@tuya-miniapp/cloud-api≥1.6.1
Additional notesRead the full notes
This API depends on cloud capabilities. Configure authorization in Development Settings - Cloud Capabilities on the Mini App Developer Platform. orderId comes from the return value of createOrderV2; paymentProvider and paymentType come from paidProviderName and paidTypeName in the paidConfigList returned by getSkuPayment. Populate commodityRelateContactInfos as needed based on the fulfillment target: for home-level fulfillment, set code: '3' (content includes home info: groupId, groupName); for device-level fulfillment, set code: '4' (content includes device info: devId, deviceName, uuid). clientInfo is optional and should be provided as required by the payment channel: when paymentProvider is apple_iap_pay, set packageName; when an alternativePay token exists, set googleIapReportToken (Google IAP reporting).

Description

Initiate order prepayment and obtain payment page information (e.g., cashier redirect URL).

Parameters

ParameterTypeRequiredDescription
YesRequest parameters

Return Value

Type: Promise<GetPrepayResult>
Prepayment information, including order ID, payment URL, and prepayment order ID

Referenced Types

interfaceGetPrepayResultPreorder (initiate payment) result
PropertyTypeDescription
orderIdstringOrder number
paymentUrlstringPayment URL used to redirect to the payment page
preFlowCodestringPrepayment order number
Extended information
enumVasPaymentOS
ValueActual ValueDescription
VasPaymentOS.ANDROID1Android
VasPaymentOS.IOS2iOS

Valid Values

VasPaymentOS
ValueDescriptionSince
1Android-
2iOS-

Examples

Request example

import { getPrepay, VasPaymentOS } from '@tuya-miniapp/cloud-api';

getPrepay({
  shopCode: 'your_shop_code',
  mallCode: 'your_mall_code',
  siteCode: 'your_site_code',
  orderId: 'your_order_id',
  os: VasPaymentOS.IOS,
  clientInfo: {},
  returnPage: '/payment-center/miniapp-result?appscheme=your_app_scheme',
  expireUrl: '/payment-center/miniapp-expire?appscheme=your_app_scheme',
  cancelPage: '/payment-center/miniapp-expire?appscheme=your_app_scheme',
  paymentProvider: 'your_paid_provider_name',
  paymentType: 'your_paid_type_name',
  commodityRelateContactInfos: [
    // For fulfillment at the home level, pass code '3' (choose one as needed)
    { code: '3', value: '{"groupId": "your_group_id", "groupName": "your_group_name"}' },
    // For fulfillment at the device level, pass code '4' (choose one as needed)
    { code: '4', value: '{"devId": "your_dev_id", "deviceName": "your_device_name", "uuid": "your_device_uuid"}' },
  ],
})
  .then(prepay => {
    console.log('Prepay info:', prepay);
  })
  .catch(error => {
    console.error('Failed to initiate prepay:', error);
  });

Response example

{
  "orderId": "your_order_id",
  "paymentUrl": "https://example.com/payment/checkout",
  "preFlowCode": "PF20231018001"
}