Alipay+ DocsAlipay+ Docs

showPaymentSheet

The showPaymentSheet API is used to show the payment sheet for the user to complete the payment after the user places an order with Alipay+. You can display the recommended Mobile Payment Providers (MPPs) that are supported by Alipay+ on the payment sheet.

Note:

  • The payment sheet mentioned in this section is also known as the Alipay+ checkout page.
  • If only one payment method is available, the payment sheet is not displayed. In this case, the user is directly redirected to the MPP client to complete the payment.

After the user selects an MPP and clicks Pay Now, the user is redirected to the MPP client to complete the payment. In the preceding process, you can receive callbacks about key events, such as when the user clicks Close or when the user clicks Pay Now.

How to handle the key events:

  • When you receive the event that the user has selected an MPP and clicked Pay Now, the SDK closes the payment sheet and redirects the user to the MPP client to complete the payment. The payment status will not be updated through callbacks. Therefore, you may need to call your server to query the payment status.
  • When the user clicks Close, the SDK closes the payment sheet. You can define custom logic to process the event.
  • If the value of the paymentData parameter is illegal, the payment sheet is not displayed and the corresponding callback is invoked to notify the caller.

About the payment sheet:

  • The payment sheet is closed only when the user clicks Close or clicks Pay Now after selecting an MPP.

Method signature

copy
public static void showPaymentSheet(Context context, String paymentData, IAPPaymentSheetEventCallback callback);

Request parameters

Name

Type

Length

Description

Required

context

Context

/

The context of the Android activity.

M

paymentData

String

/

The payment data that is used for rendering the payment sheet.

M

callback

IAPPaymentSheetEventCallback

/

The callback that is used to return the status of the payment sheet. See callback for details.

M

callback

Name

Android type

Length

Description

Required

sheetEvent

IAPPaymentSheetEvent

/

An object that describes the event that occurred when the status of the payment sheet changed.

O

Response parameters

N/A

Sample

copy
String paymentData = "XXX";
AlipayPlusClient.showPaymentSheet(context, paymentData, new IAPPaymentSheetEventCallback<IAPPaymentSheetEvent>() {

    public void onSheetEvent(IAPPaymentSheetEvent event) {
        switch(event.name) {
            case "EVENT_SELECT_AND_PAY":
                //your own logic
                break;
            case "EVENT_THROW_EXCEPTION":
                //your own logic
                break;   
            case "EVENT_USER_CANCEL":
                //your own logic
                break;
            case "EVENT_SHOW_SUCCESS":
                //your own logic
                break;
            case "EVENT_PAYMENT_SUCCESS":
                //your own logic after payment success
                //Currently, this type of event may occur only after you import                 //Alipay SDK to optimize the Alipay payment experience.
                break;
            case "EVENT_PAYMENT_FAILED":
                //your own logic after payment failure
                //Currently, this type of event may occur only after you import                 //Alipay SDK to optimize the Alipay payment experience.
                break;
            case "EVENT_PAYMENT_CANCELED":
                //your own logic after payment cancelation
                //Currently, this type of event may occur only after you import                 //Alipay SDK to optimize the Alipay payment experience.
                break;
            case "EVENT_PAYMENT_EXCEPTION":
                //your own logic after payment interruption
                //Currently, this type of event may occur only after you import                 //Alipay SDK to optimize the Alipay payment experience.
                break;
            case "EVENT_PAYMENT_PROCESSING":
                //your own logic after payment finishes but status is ongoing
                //Currently, this type of event may occur only after you import                 //Alipay SDK to optimize the Alipay payment experience.
                break;
        
        }
    }

})