0% found this document useful (0 votes)
9 views3 pages

Jazzcash PaymentApi

Uploaded by

HASSAN NAZIR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Jazzcash PaymentApi

Uploaded by

HASSAN NAZIR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Make Payment Api:

-----------------

Required Params:
----------------
pp_MerchantID
pp_Password
pp_PaymentToken
pp_TxnRefNo
pp_Amount
pp_TxnCurrency
pp_TxnDateTime
pp_BillReference
pp_Description
pp_TxnExpiryDateTime

-----------------------------------------------------------------------------------
---------------------------
Sample Values:
-------------
paymentUrl:
"https://sandbox.jazzcash.com.pk/ApplicationAPI/API/4.0/purchase/domwallettransacti
onviatoken"
refundUrl:
"https://sandbox.jazzcash.com.pk/ApplicationAPI/API/Purchase/domwalletrefundtransac
tion"
merchantId: "MC59401"
password: "0590e3syzx"
amount: "700"
integritySalt: "049xag15gv"
paymentType: "wallet"
-----------------------------------------------------------------------------------
---------------------------

Map makePayment (String token = "", long msisdn) {


String url = Holders.config['jazzCash.paymentUrl']
String merchantId = Holders.config['jazzCash.merchantId']
String password = Holders.config['jazzCash.password']
String amount = Holders.config['jazzCash.amount']
String integritySalt = Holders.config["jazzCash.integritySalt"]
String res = ""
Map result = [:]
String postUrl = url
Map header = [:]
header.put("Content-Type", "application/json")

String body = """{


"pp_MerchantID": "$merchantId",
"pp_SubMerchantID": "",
"pp_Password": "$password",
"pp_PaymentToken": "$token",
"pp_ProductID": "",
"pp_TxnRefNo": "${generateUniqueTxnRefNo()}",
"pp_Amount": "$amount",
"pp_TxnCurrency": "PKR",
"pp_TxnDateTime": "${Durations.currentDateTime}",
"pp_BillReference": "billRef",
"pp_Description": "Payment Request",
"pp_TxnExpiryDateTime": "${Durations.getCurrentDateTime(1)}",
"pp_SecureHash": "",
"pp_DiscountedAmount": "",
"ppmpf_1": "",
"ppmpf_2": "",
"ppmpf_3": "",
"ppmpf_4": "",
"ppmpf_5": ""
}
}"""
try {
String payLoad = generateHash(body, integritySalt)
subscriptionService.userLogging("JazzCashPaymentReq",msisdn, ",
$payLoad")
res = httpRequestService.doPost(postUrl, payLoad, header)
subscriptionService.errorLogging("JazzCashPaymentRes",msisdn,",$res")
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(res)

if (parsedJson?.get("pp_ResponseCode") != null &&


parsedJson?.get("pp_ResponseCode") == "000") {
subscriptionService.userLogging("JazzCashPaymentRes", msisdn,",$
{parsedJson?.get("pp_ResponseMessage")}")
result = [pp_ResponseCode: "${parsedJson?.get("pp_ResponseCode")}",
pp_ResponseMessage: "$
{parsedJson?.get("pp_ResponseMessage")}",
"pp_RetreivalReferenceNo": "$
{parsedJson?.get("pp_RetreivalReferenceNo")}"]
} else{
subscriptionService.userLogging("JazzCashPaymentRes",
msisdn,",Error: ${parsedJson?.get("pp_ResponseMessage")}")
result = [pp_ResponseCode: "${parsedJson?.get("pp_ResponseCode")}",
pp_ResponseMessage: "${parsedJson?.get("pp_ResponseMessage")}"]
}
} catch (Exception e) {
result = null
subscriptionService.userLogging("JazzCashPaymentRes", msisdn,",Error")
log.error(e.printStackTrace())
}
return result
}

// Generating Unique Reference No

String generateUniqueTxnRefNo() {
def random = new Random()
def timestamp = Instant.now().toEpochMilli()
def randomNumber = random.nextInt(100)
def uniqueTxnRefNo = "TRN${timestamp}${randomNumber}"
return uniqueTxnRefNo
}

// Generating Hash

def generateHash(body, secretKey = "049xag15gv") {


def separator = "&"
def jsonMap = new JsonSlurper().parseText(body)

def fields = jsonMap.entrySet().toList().sort { a, b ->


a.key.compareTo(b.key) }
def concatenatedFields = fields.collect { it.value }.findAll
{ it }.join(separator)

def dataToHash = "${secretKey}${separator}${concatenatedFields}"

def hmacSha256 = Mac.getInstance("HmacSHA256")


hmacSha256.init(new SecretKeySpec(secretKey.bytes, "HmacSHA256"))
byte[] hashBytes = hmacSha256.doFinal(dataToHash.bytes)
def hashHexString = hashBytes.collect { String.format("%02X",
it) }.join().toUpperCase()
jsonMap["pp_SecureHash"] = hashHexString
return new JsonBuilder(jsonMap).toPrettyString()
}

You might also like