payfort "response_message":"带有标记化的无效命令



我正在使用payfort进行支付过程

当向payfort api发送请求以给我一个token_name时,请求的响应使返回payfort"response_message":"Invalid commandTOKENIZATION

在payfort配置文件中激活商家页面通道,并设置其中的所有信息,如重定向链接和url等

并发送所有强制参数,签名成功,您可以在以下文档中看到请求参数

payfort文档

我正在使用spring boot并尝试从邮递员和角形式发送请求到我的api,然后在处理签名后重定向到payfortAPI

我正在使用测试url环境来测试来自payfort的交易

和我尝试发送请求从邮递员测试url环境从payfort不使用春季启动,但将返回相同的响应

和下面我的代码

@Data
public class Payment extends Signature implements ISignature{

private String expiry_date;
private String card_number;
private String card_security_code;
private String paymentSignature;
private String card_holder_name;
/*
public Payment(){
super();
}*/
public String getSignature(){
return paymentSignature;
}
public void setSignature() throws NoSuchAlgorithmException {
paymentSignature=createSign();
}
@Override
public String createSign() throws NoSuchAlgorithmException {
Map<String, Object> requestMap = new HashMap<>();
requestMap.put("service_command", this.getService_command());
requestMap.put("access_code", this.getAccess_code());
requestMap.put("merchant_identifier", this.getMerchant_identifier());
requestMap.put("merchant_reference", this.getMerchant_reference());
requestMap.put("language", this.getLanguage());
requestMap.put("expiry_date", this.getExpiry_date());
requestMap.put("card_number", this.getCard_number());
requestMap.put("card_security_code", this.getCard_security_code());
requestMap.put("card_holder_name",this.getCard_holder_name());
//order by key
requestMap = requestMap.entrySet().stream().sorted(Map.Entry.comparingByKey())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
String requestString = "saAbdalrhman0788&*";
for(Map.Entry<String, Object> entry: requestMap.entrySet())
requestString += entry.getKey() + "=" + entry.getValue();
requestString+= "Abdalrhman0788&*";
System.out.println("requestString = " + requestString);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashed = digest.digest(requestString.getBytes(StandardCharsets.UTF_8));
String signature = javax.xml.bind.DatatypeConverter.printHexBinary(hashed);
System.out.println("signature = " + signature);
return signature;
}

这里是我调用payfort api的服务

public String CreateTokenization(Payment payment) throws NoSuchAlgorithmException, URISyntaxException {
fillTokenization(payment);
HttpHeaders headers = new HttpHeaders();
headers.set("Content-type", "application/json" );

Map<String,Object>  body=new HashMap<>();
body.put("service_command",payment.getService_command());
body.put("access_code",payment.getAccess_code());
body.put("merchant_identifier", payment.getMerchant_identifier());
body.put("merchant_reference", payment.getMerchant_reference());
body.put("expiry_date",payment.getExpiry_date());
body.put("card_number",payment.getCard_number());
body.put("card_security_code",payment.getCard_security_code());
body.put("signature",payment.getSignature());
// add request param before send the request to amazon payment api
URI uri = new URI(testEnvironment);
HttpEntity<Object> request = new HttpEntity<>(body, headers);
ResponseEntity<String> res= restTemplate.postForEntity(uri,request,String.class);
System.out.println("res = " + res.toString());
return res.toString();
}

,我将把这些数据发送给付款

{
"service_command":"TOKENIZATION",
"access_code":"LVQEEDAfI1qbZW0wXbsb",
"merchant_identifier":"5f803bfd",
"merchant_reference":"00658azx1",
"language":"en",
"expiry_date":"1125",
"card_number":"4005550000000001",
"card_security_code":"123",

"signature"35 d8d45435741d40619e947b0a8a7c8675bbd42fcb0c2bfc12c519cee48f3b3f"}

这是我从payfort

得到的完整回复
<200,{"response_code":"00004","service_command":"TOKENIZATION","card_number":"400555******0001","response_message":"Invalid command","signature":"da3f35fe27802719db31e500674025fa14d255c74a66c7005d2a720bb437e0ed","merchant_identifier":"5f803bfd","merchant_reference":"00658azx1","access_code":"BhSPWubm9lsp577tsv7J","expiry_date":"1125","status":"00"},[Date:"Thu, 28 Oct 2021 21:11:17 GMT", Content-Type:"application/json;charset=UTF-8", Content-Length:"345", Connection:"keep-alive", Accept-Charset:"big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp", X-Amzn-Trace-Id:"Root=1-617b11f5-fcab24484764e302621fd107;", X-Powered-By:"Undertow/1", CF-Cache-Status:"DYNAMIC", Expect-CT:"max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"", Server:"cloudflare", CF-RAY:"6a5727dccd6e5caa-FRA"]>

如果发送无效的符号将返回相同的响应

我发现签名错误,请删除以下行

requestMap.put("expiry_date", this.getExpiry_date());
requestMap.put("card_number", this.getCard_number());
requestMap.put("card_security_code", this.getCard_security_code());
requestMap.put("card_holder_name",this.getCard_holder_name());

因为我在payfort文档

中发现了这个注释

请记住-请不要在如果您使用的是自定义商家页面,则计算签名集成令牌化请求:card_security_code,卡号,过期日期,card_holder_name, memorber_me .

唯一需要的TOKENIZATION必须传递的参数为。

'service_command'     => 'TOKENIZATION',
'merchant_reference'  => your merchant Reference,
'access_code'         => your access code,
'merchant_identifier' => your merchant id,
'language'            => your preferred language in payment,
'return_url'          => your return url where you will get  response of payfort,

更进一步,你必须使用PURCHASE命令,如果前面的响应码为18000。

最新更新