Offer APIs
The following APIs used for offers with Android Core SDK:
Fetch Offer Details
Use this API to fetch the offer list available for the merchant.
To integrate thisβ―APIβ―call the fetchOfferDetails pass the requestData as parameters as shown in the code snippet below:
payuConfig = new PayuConfig();
payuConfig.setEnvironment(PayuConstants.STAGING_ENV);
V2ApiTask v2ApiTask = new V2ApiTask(merchantKey, payuConfig);
FetchOfferApiRequest fetchOfferApiRequest = new FetchOfferApiRequest.Builder().setAmount(100.00).setUserToken("56789067890").build();
v2ApiTask.getOffers(fetchOfferApiRequest, new HashGenerationListener() {
Β Β @Override
Β Β public void generateSignature(HashMap<String, String> hashMap, HashCompletionListener hashCompletionListener) {
Β Β Β Β Β Β String hashName = hashMap.get(PayuConstants.CP_HASH_NAME);
Β Β Β Β Β Β String hashData = hashMap.get(PayuConstants.CP_HASH_STRING);
Β Β Β Β Β Β Log.d(TAG, "generateSignature: " + hashName);
Β Β Β Β Β Β Log.d(TAG, "generateSignature: " + hashData);
Β Β Β Β Β Β String hash = HashGenerationUtils.generateHashFromSDK(hashData, salt);
Β Β Β Β Β Β HashMap hashMap1 = new HashMap();
Β Β Β Β Β Β hashMap1.put(hashName, hash);
Β Β Β Β Β Β hashCompletionListener.onSignatureGenerated(hashMap1);Β // If you are passing wrong Hash then you will get null response
Β Β }
}, new FetchOfferDetailsListener() {
Β Β @Override
Β Β public void onFetchOfferDetailsResponse(PayuResponse payuResponse) {
Β Β Β Β Β Β Log.d(TAG, "onFetchOfferDetailsResponse: " + payuResponse.getRawResponse());
Β Β }
});
Validate Offer API
Use this API to validate the offer for the merchants.
To integrate thisβ―APIβ―call the methodβ― validateOfferDetails and pass the requestData as parameters as shown in the code snippet below:
List<String> offerKey = new ArrayList<>();
offerKey.add("<pass the offer key>");
PaymentDetailsForOffer paymentDetailsForOffer = new PaymentDetailsForOffer.Builder().setPaymentCode("CC").setCardNumber("5123456789012346").setCategory("CREDITCARD").build();
UserDetailsForOffer userDetailsForOffer = new UserDetailsForOffer.Builder().setUserToken("56789067890").build();
payuConfig = new PayuConfig();
payuConfig.setEnvironment(PayuConstants.STAGING_ENV);
V2ApiTask v2ApiTask = new V2ApiTask(merchantKey, payuConfig);
ValidateOfferRequest validateOfferRequest = new ValidateOfferRequest.Builder().setAmount("100.00").setOfferKey(offerKey).setPaymentDetails(paymentDetailsForOffer).setuserDetails(userDetailsForOffer).setAutoApply(false).build();
v2ApiTask.validateOffers(validateOfferRequest, new HashGenerationListener() {
Β Β @Override
Β Β public void generateSignature(HashMap<String, String> hashMap, HashCompletionListener hashCompletionListener) {
Β Β Β Β Β Β String hashName = hashMap.get(PayuConstants.CP_HASH_NAME);
Β Β Β Β Β Β String hashData = hashMap.get(PayuConstants.CP_HASH_STRING);
Β Β Β Β Β Β Log.d(TAG, "generateSignature: " + hashName);
Β Β Β Β Β Β Log.d(TAG, "generateSignature: " + hashData);
Β Β Β Β Β Β String hash = HashGenerationUtils.generateHashFromSDK(hashData, salt);
Β Β Β Β Β Β HashMap hashMap1 = new HashMap();
Β Β Β Β Β Β hashMap1.put(hashName, hash);
Β Β Β Β Β Β hashCompletionListener.onSignatureGenerated(hashMap1);Β // If you are passing wrong Hash then you will get null response
Β Β }
}, new ValidateOfferApiListener() {
Β Β @Override
Β Β public void onValiDateOfferResponse(PayuResponse payuResponse) {
Β Β Β Β Β Β Log.d(TAG, "onValiDateOfferResponse: " + payuResponse.getRawResponse());
Β Β }
});
Updated 2 months ago