Initiate the Payment
(Mandatory Step)
Step 4: Initiate the Payment
Initialize the PayUCheckoutPro SDK by passing the payment parameters prepared in the previous step and a reference to the transaction listener.
PayUCheckoutPro.open(
Activity activity,
PayUPaymentParams payUPaymentParams,
PayUCheckoutProListener payUCheckoutProListener)
Sample Code
PayUCheckoutPro.open(
this,
payUPaymentParams,
new PayUCheckoutProListener() {
@Override
public void onPaymentSuccess(Object response) {
//Cast response object to HashMap
HashMap<String,Object> result = (HashMap<String, Object>) response;
String payuResponse = (String)result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
String merchantResponse = (String) result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE);
}
@Override
public void onPaymentFailure(Object response) {
//Cast response object to HashMap
HashMap<String,Object> result = (HashMap<String, Object>) response;
String payuResponse = (String)result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
String merchantResponse = (String) result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE);
}
@Override
public void onPaymentCancel(boolean isTxnInitiated) {
}
@Override
public void onError(ErrorResponse errorResponse) {
String errorMessage = errorResponse.getErrorMessage();
}
@Override
public void setWebViewProperties(@Nullable WebView webView, @Nullable Object o) {
//For setting webview properties, if any. Check Customized Integration section for more details on this
}
@Override
public void generateHash(HashMap<String, String> valueMap, PayUHashGenerationListener hashGenerationListener) {
String hashName = valueMap.get(PayUCheckoutProConstants.CP_HASH_NAME);
String hashData = valueMap.get(PayUCheckoutProConstants.CP_HASH_STRING);
if (!TextUtils.isEmpty(hashName) && !TextUtils.isEmpty(hashData)) {
//Do not generate hash from local, it needs to be calculated from server side only. Here, hashString contains hash created from your server side.
String hash = hashString;
HashMap<String, String> dataMap = new HashMap<>();
dataMap.put(hashName, hash);
hashGenerationListener.onHashGenerated(dataMap);
}
}
}
);
Last updated
Was this helpful?