我正在使用 payfort 进行付款流程
当向 payfort api 发送请求以给我一个 token_name 请求的响应时返回 "response_message":"Invalid command
payfortTOKENIZATION
我在 payfort 配置文件中激活了商家页面通道,并在其中设置了所有信息,例如重定向链接和 url 等等
并发送所有带有成功签名的强制参数,您可以在以下文档中看到请求参数
我正在使用spring boot并尝试从邮递员和角度形式发送请求到我的api,然后在处理签名后重定向到payfortAPI
我正在使用测试 url 环境来测试来自 payfort 的交易
我尝试从邮递员发送请求以在不使用弹簧启动的情况下从 payfort 测试 url 环境,但会返回相同的响应
以下是我的代码
@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",
“签名”:“35D8D45435741D40619E947B0A8A7C8675BBD42FCB0C2BFC12C519CEE48F3B3F”}
这是我对 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"]>
如果发送无效符号将返回相同的响应