handlePageResult
The handlePageResult API is called by the super app to send the processing result from the React Native page back to the SDK.
Method signature
function handlePageResult(
traceId: string,
pageResult: Object,
extra?: {
success?: (success: BaseSuccess) => void;
error?: (error: BaseError) => void;
}
)
Request parameters
Field | Data type | Required | Description |
traceId | string | Yes | The unique ID that is assigned by the SDK to identify a specific method call. This parameter correlates the processing result with the request. Obtain its value from the object that the SDK passes to the React Native page upon opening. |
pageResult | Object | Yes | An object that contains the processing result from the React Native page. Construct the object by conforming to one of the following data models depending on the method that triggers the page:
|
extra | Object | No | An extended attribute that is used to provide additional information if necessary. The included parameters are:
|
Response parameters
N/A
Result codes
Result code | Result message | Description | Further action |
1000 |
| The SDK opens the mini program successfully. | N/A |
2000 | The result message varies depending on the error that occurs. | The SDK encounters an error when attempting to open the mini program. | Refer to the result message for specific actions. |
Sample
import React from 'react';
import {
StyleSheet,
Text,
View,
SafeAreaView,
StatusBar,
Button,
} from 'react-native';
import { Component, useState, useEffect, useContext } from 'react';
import Toast from 'react-native-root-toast';
import { handlePageResult, openApp } from 'iapminiprogram-rn';
import type {
PaymentResult,
BaseSuccess,
BaseError,
APIContext,
PaymentRequest,
ParsePay,
} from 'iapminiprogram-rn';
import { PAYMENT_CODE } from 'iapminiprogram-rn';
function Pay(initialProps: ParsePay) {
return (
<SafeAreaView style={styles.container}>
<Text style={styles.titleText}>Pay</Text>
<View style={styles.divider} />
<Button
title="Pay Success"
onPress={() =>
handlePayOperate(PAYMENT_CODE.CODE_SUCCESS, 'Pay Success')
}
color="#841584"
/>
<View style={styles.divider} />
<Button
title="Pay fail"
onPress={() => handlePayOperate(PAYMENT_CODE.CODE_FAILURE, 'Pay fail')}
color="#841584"
/>
<View style={styles.divider} />
<Button
title="Pending Pay"
onPress={() =>
handlePayOperate(PAYMENT_CODE.CODE_PENDING, 'Pending Pay')
}
color="#841584"
/>
<View style={styles.divider} />
<Button
title="Cancel Pay"
onPress={() =>
handlePayOperate(PAYMENT_CODE.CODE_USER_CANCEL, 'Cancel Pay')
}
color="#841584"
/>
<View style={styles.divider} />
<Button
title="Pay Off"
onPress={() => handlePayOperate('', '')}
color="#841584"
/>
<View style={styles.divider} />
<Button title="Open MiniProgram" onPress={openMiniApp} color="#841584" />
</SafeAreaView>
);
function handlePayOperate(resultCode: string, resultMessage: string) {
var result: PaymentResult = {
resultCode: resultCode,
resultMessage: resultMessage,
};
handlePageResult(initialProps.traceId, result, {
success: (success: BaseSuccess) => {
Toast.show('success:' + success.msg);
},
error: (error: BaseError) => {
Toast.show('error:' + error.errorMsg);
},
});
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: StatusBar.currentHeight,
marginHorizontal: 16,
},
titleText: {
fontSize: 20,
fontWeight: 'bold',
},
divider: {
height: 20,
},
title: {
fontSize: 24,
},
});
export default Pay;