JazzCash 支付与 API REACT NATIVE 集成
我一直在尝试将 JazzCash 支付与 JazzCash Sandbox 集成,但我在服务器响应中收到相同的错误
请提供 pp_SecureHash 的有效值。
我尝试了各种方法来创建 HMAC-SHA256
文档链接 JZ 支付
API LINK : https://sandbox.jazzcash.com.pk/SandboxDocumentation/v4.2/ApiReferences.html#wa
https:// payments.jazzcash.com.pk/SandboxDocumentation/features.html
我已经尝试过 cryptojs 和来自谷歌的其他硬编码,
这是我的代码。抱歉,编码很粗糙,我仍在学习。
import { Text, View } from 'react-native'
import React, { Component } from 'react'
import moment from 'moment'
import CryptoJS from 'crypto-js'
import crypto from 'crypto-js'
import hmacSHA256 from 'crypto-js/hmac-sha256';
import hmacSHA512 from 'crypto-js/hmac-sha512';
import Base64 from 'crypto-js/enc-base64';
import enc_utf8 from 'crypto-js/enc-utf8';
import Utf8 from 'crypto-js/enc-utf8';
const JAZZCASH_HTTP_POST_URL = 'https://sandbox.jazzcash.com.pk/ApplicationAPI/API/2.0/Purchase/DoMWalletTransaction'
const INTEGRITY_KEY = "318c8uvg51"
var arr = []
export default class JAzzCash extends Component {
state = {
pp_Language: "EN",
pp_MerchantID: "MC35289",
pp_SubMerchantID: "",
pp_Password: "vy0240sbe0",
pp_TxnRefNo: "",
pp_MobileNumber: "03411728699",
pp_CNIC: "345678",
pp_Amount: "10000",
pp_TxnType: "MWALLET",
pp_DiscountedAmount: "",
pp_TxnCurrency: "PKR",
pp_TxnDateTime: "",
pp_BillReference: "BillRef",
pp_Description: "Hello",
pp_TxnExpiryDateTime: "",
pp_SecureHash: "",
ppmpf_1: "",
ppmpf_2: "",
ppmpf_3: "",
ppmpf_4: "",
ppmpf_5: ""
}
secureHash = (data) => {
// console.log(JSON.stringify(data));
// → '{"b":"foo","c":"bar","a":"baz"}'
const ordered = Object.keys(data).sort().reduce(
(obj, key) => {
obj[key] = data[key];
return obj;
},
{}
);
// console.log(JSON.stringify(ordered));
var hash = ""
Object.entries(ordered).forEach(
([key, value]) => {
if (value != "") {
hash += '&' + value
}
}
);
// console.log(hash);
return hash;
}
convertToSHA = async (string) => {
await sha256(string).then((hash) => {
console.log(hash);
});
};
componentDidMount = async () => {
var date = new Date()
date = date.getFullYear() + ("0" + (date.getMonth())).slice(-2) + ("0"+date.getDate()).slice(-2) + ("0" + date.getHours()).slice(-2) + ("0" + date.getMinutes()).slice(-2) + ("0" + date.getSeconds()).slice(-2)
var date1 = new Date()
date1.setHours(date1.getHours() + 1);
date1 = date1.getFullYear() + ("0" + (date1.getMonth())).slice(-2) + ("0" + date1.getDate()).slice(-2) + ("0" + date1.getHours()).slice(-2) + ("0" + date1.getMinutes()).slice(-2) + ("0" + date1.getSeconds()).slice(-2)
var tXID = 'T' + date
await this.setState({
pp_TxnDateTime: date,
pp_TxnExpiryDateTime: date1,
pp_TxnRefNo: 'T' + date,
// pp_BillReference: 'T' + date,
})
var hash = this.secureHash(this.state)
hash = INTEGRITY_KEY + hash; //Integritykey + hashString
console.log('HASH======> ', hash);
const hmacDigest = hmacSHA256(hash, INTEGRITY_KEY).toString();
console.log('SecureHash======> ', hmacDigest);
// const hmacDigest11 = Utf8.stringify(hmacSHA256(hash, INTEGRITY_KEY))
// let encData = CryptoJS.enc.Utf8.stringify(hash, INTEGRITY_KEY)
// console.log('SecureHash11======> ', encData);
// console.log("HASH ,", hash);
await this.setState({
"pp_SecureHash": hmacDigest
})
// await console.log("SecureHash1 ", this.state);
fetch(JAZZCASH_HTTP_POST_URL, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(this.state)
})
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data.pp_ResponseMessage)
});
}
render() {
return (
<View>
<Text>JAzzCash</Text>
</View>
)
}
}
I have been trying to integrate JazzCash payment with JazzCash Sandbox, but I am getting the same error in response from the server
Please provide valid value for pp_SecureHash.
I have tried various methods to create HMAC-SHA256
Documentation Link JZ PAYMENT
API LINK : https://sandbox.jazzcash.com.pk/SandboxDocumentation/v4.2/ApiReferences.html#wa
https://payments.jazzcash.com.pk/SandboxDocumentation/features.html
I have tried cryptojs and other hard codings from google
heres my code. sorry for rough coding i am still learning.
import { Text, View } from 'react-native'
import React, { Component } from 'react'
import moment from 'moment'
import CryptoJS from 'crypto-js'
import crypto from 'crypto-js'
import hmacSHA256 from 'crypto-js/hmac-sha256';
import hmacSHA512 from 'crypto-js/hmac-sha512';
import Base64 from 'crypto-js/enc-base64';
import enc_utf8 from 'crypto-js/enc-utf8';
import Utf8 from 'crypto-js/enc-utf8';
const JAZZCASH_HTTP_POST_URL = 'https://sandbox.jazzcash.com.pk/ApplicationAPI/API/2.0/Purchase/DoMWalletTransaction'
const INTEGRITY_KEY = "318c8uvg51"
var arr = []
export default class JAzzCash extends Component {
state = {
pp_Language: "EN",
pp_MerchantID: "MC35289",
pp_SubMerchantID: "",
pp_Password: "vy0240sbe0",
pp_TxnRefNo: "",
pp_MobileNumber: "03411728699",
pp_CNIC: "345678",
pp_Amount: "10000",
pp_TxnType: "MWALLET",
pp_DiscountedAmount: "",
pp_TxnCurrency: "PKR",
pp_TxnDateTime: "",
pp_BillReference: "BillRef",
pp_Description: "Hello",
pp_TxnExpiryDateTime: "",
pp_SecureHash: "",
ppmpf_1: "",
ppmpf_2: "",
ppmpf_3: "",
ppmpf_4: "",
ppmpf_5: ""
}
secureHash = (data) => {
// console.log(JSON.stringify(data));
// → '{"b":"foo","c":"bar","a":"baz"}'
const ordered = Object.keys(data).sort().reduce(
(obj, key) => {
obj[key] = data[key];
return obj;
},
{}
);
// console.log(JSON.stringify(ordered));
var hash = ""
Object.entries(ordered).forEach(
([key, value]) => {
if (value != "") {
hash += '&' + value
}
}
);
// console.log(hash);
return hash;
}
convertToSHA = async (string) => {
await sha256(string).then((hash) => {
console.log(hash);
});
};
componentDidMount = async () => {
var date = new Date()
date = date.getFullYear() + ("0" + (date.getMonth())).slice(-2) + ("0"+date.getDate()).slice(-2) + ("0" + date.getHours()).slice(-2) + ("0" + date.getMinutes()).slice(-2) + ("0" + date.getSeconds()).slice(-2)
var date1 = new Date()
date1.setHours(date1.getHours() + 1);
date1 = date1.getFullYear() + ("0" + (date1.getMonth())).slice(-2) + ("0" + date1.getDate()).slice(-2) + ("0" + date1.getHours()).slice(-2) + ("0" + date1.getMinutes()).slice(-2) + ("0" + date1.getSeconds()).slice(-2)
var tXID = 'T' + date
await this.setState({
pp_TxnDateTime: date,
pp_TxnExpiryDateTime: date1,
pp_TxnRefNo: 'T' + date,
// pp_BillReference: 'T' + date,
})
var hash = this.secureHash(this.state)
hash = INTEGRITY_KEY + hash; //Integritykey + hashString
console.log('HASH======> ', hash);
const hmacDigest = hmacSHA256(hash, INTEGRITY_KEY).toString();
console.log('SecureHash======> ', hmacDigest);
// const hmacDigest11 = Utf8.stringify(hmacSHA256(hash, INTEGRITY_KEY))
// let encData = CryptoJS.enc.Utf8.stringify(hash, INTEGRITY_KEY)
// console.log('SecureHash11======> ', encData);
// console.log("HASH ,", hash);
await this.setState({
"pp_SecureHash": hmacDigest
})
// await console.log("SecureHash1 ", this.state);
fetch(JAZZCASH_HTTP_POST_URL, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(this.state)
})
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data.pp_ResponseMessage)
});
}
render() {
return (
<View>
<Text>JAzzCash</Text>
</View>
)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论