i am using payfort for payment process
when send request to payfort api to give me a token_name the response from request make return payfort "response_message":"Invalid command
with TOKENIZATION
i active Merchant page channel in payfort profile and set all information inside it like redirection link and url and soo on
and send all mandatory param with successful signature you can see request param in this following document
i am using spring boot and try send request from postman and angular form to my api and then redirect to payfortAPI after handling signature
i am using test url enviroment to test transaction from payfort
and i try send request from post man to test url enviroment from payfort without using spring boot but will return same response
and the following here my code
@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;
}
and here my service to call 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();
}
and i will send this data to payment
{
"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":"35D8D45435741D40619E947B0A8A7C8675BBD42FCB0C2BFC12C519CEE48F3B3F"}
and this is my full response from 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"]>
if send invalid sign will return the same response
2
Answers
i found the error in signature just remove following line
because i found this note in payfort document
The only required parameter you must pass for TOKENIZATION will be.
For further you have to use PURCHASE command if the previous response code will be 18000.