From f40730381286a42ce3b1c22ed25f0e64608a8aa1 Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Sun, 21 Aug 2022 13:53:05 +0200 Subject: [PATCH 1/7] fix quickPaymeny response type --- lib/src/main/java/com/tuti/api/TutiApiClient.java | 2 +- lib/src/main/java/com/tuti/api/data/PaymentToken.java | 1 + lib/src/main/java/com/tuti/api/ebs/EBSRequest.java | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/tuti/api/TutiApiClient.java b/lib/src/main/java/com/tuti/api/TutiApiClient.java index 899b8b1..6428fd2 100644 --- a/lib/src/main/java/com/tuti/api/TutiApiClient.java +++ b/lib/src/main/java/com/tuti/api/TutiApiClient.java @@ -202,7 +202,7 @@ public void getPaymentToken(PaymentToken request, ResponseCallable } public void quickPayment(EBSRequest request, ResponseCallable onResponse, ErrorCallable onError) { - sendRequest(RequestMethods.POST, serverURL + Operations.QuickPayment, request, TutiResponse.class, TutiResponse.class, onResponse, onError, null); + sendRequest(RequestMethods.POST, serverURL + Operations.QuickPayment, request, TutiResponse.class, PaymentToken.class, onResponse, onError, null); } public Thread sendRequest(RequestMethods method, String URL, Object requestToBeSent, Type ResponseType, Type ErrorType, ResponseCallable onResponse, ErrorCallable onError, Map headers) { diff --git a/lib/src/main/java/com/tuti/api/data/PaymentToken.java b/lib/src/main/java/com/tuti/api/data/PaymentToken.java index 7fed25a..44ce424 100644 --- a/lib/src/main/java/com/tuti/api/data/PaymentToken.java +++ b/lib/src/main/java/com/tuti/api/data/PaymentToken.java @@ -104,6 +104,7 @@ public void setCardTobePaid(String cardTobePaid) { @SerializedName("toCard") private String cardTobePaid; + private EBSResponse transaction; @SerializedName("is_paid") diff --git a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java index c0bac51..e6f7eef 100644 --- a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java +++ b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java @@ -183,6 +183,10 @@ public String getQuickPayToken() { return quickPayToken; } + /** + * This is used to pass-on a payment token (scanned via eg QR) + * @param quickPayToken + */ public void setQuickPayToken(String quickPayToken) { this.quickPayToken = quickPayToken; } From d7ae87450227334ce48d6bffa50433c90b9c913f Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Sun, 21 Aug 2022 14:07:24 +0200 Subject: [PATCH 2/7] fix quickPaymeny response type --- lib/src/main/java/com/tuti/api/TutiApiClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/tuti/api/TutiApiClient.java b/lib/src/main/java/com/tuti/api/TutiApiClient.java index 6428fd2..8f7dabf 100644 --- a/lib/src/main/java/com/tuti/api/TutiApiClient.java +++ b/lib/src/main/java/com/tuti/api/TutiApiClient.java @@ -201,8 +201,8 @@ public void getPaymentToken(PaymentToken request, ResponseCallable sendRequest(RequestMethods.GET, serverURL + Operations.GetPaymentToken, request, TutiResponse.class, TutiResponse.class, onResponse, onError, null); } - public void quickPayment(EBSRequest request, ResponseCallable onResponse, ErrorCallable onError) { - sendRequest(RequestMethods.POST, serverURL + Operations.QuickPayment, request, TutiResponse.class, PaymentToken.class, onResponse, onError, null); + public void quickPayment(EBSRequest request, ResponseCallable onResponse, ErrorCallable onError) { + sendRequest(RequestMethods.POST, serverURL + Operations.QuickPayment, request, PaymentToken.class, PaymentToken.class, onResponse, onError, null); } public Thread sendRequest(RequestMethods method, String URL, Object requestToBeSent, Type ResponseType, Type ErrorType, ResponseCallable onResponse, ErrorCallable onError, Map headers) { From fe4470a1ab5b95729a7c5565359b0737a1a7e623 Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Sun, 21 Aug 2022 14:31:57 +0200 Subject: [PATCH 3/7] Add ipin encryption to noebs --- .../java/com/tuti/api/ebs/EBSRequest.java | 78 +++++++++++++++++++ .../java/com/tuti/api/TutiApiClientTest.java | 16 ++++ 2 files changed, 94 insertions(+) create mode 100644 lib/src/test/java/com/tuti/api/TutiApiClientTest.java diff --git a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java index e6f7eef..c5ef069 100644 --- a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java +++ b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java @@ -1,8 +1,15 @@ package com.tuti.api.ebs; import com.google.gson.annotations.SerializedName; +import com.sun.jersey.core.util.Base64; import java.io.Serializable; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.X509EncodedKeySpec; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -10,6 +17,11 @@ import java.util.Locale; import java.util.UUID; +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + public class EBSRequest implements Serializable { @SerializedName("UUID") @@ -17,6 +29,17 @@ public class EBSRequest implements Serializable { private final String tranDateTime = getDate(); private final String applicationId = "TutiPay"; + private String pubKey; + + public EBSRequest(String pubKey) { + this.pubKey = pubKey; + setEncryptedIPIN(pubKey); + } + + public EBSRequest() { + + } + public String getAuthenticationType() { return authenticationType; } @@ -401,6 +424,61 @@ public String getPhoneNumber() { public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } + + public void setEncryptedIPIN(String pubKey) { + this.IPIN = getIPINBlock(ipin, pubKey, this.uuid); + } + + private String getIPINBlock(String ipin, + String publicKey, String uuid) { + // clear ipin = uuid + IPIN + String cleraIpin = uuid + ipin; + + // prepare public key, get public key from its String representation as + // base64 + byte[] keyByte = Base64.decode(publicKey); + // generate public key + X509EncodedKeySpec s = new X509EncodedKeySpec(keyByte); + KeyFactory factory = null; + try { + factory = KeyFactory.getInstance("RSA"); + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Key pubKey = null; + try { + pubKey = factory.generatePublic(s); + } catch (InvalidKeySpecException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + // construct Cipher with encryption algrithm:RSA, cipher mode:ECB and padding:PKCS1Padding + Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + cipher.init(Cipher.ENCRYPT_MODE, pubKey); + // calculate ipin, encryption then encoding to base64 + ipin = (new String(Base64.encode(cipher.doFinal(cleraIpin + .getBytes())))); + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchPaddingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvalidKeyException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalBlockSizeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (BadPaddingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ipin; + } + } diff --git a/lib/src/test/java/com/tuti/api/TutiApiClientTest.java b/lib/src/test/java/com/tuti/api/TutiApiClientTest.java new file mode 100644 index 0000000..b780697 --- /dev/null +++ b/lib/src/test/java/com/tuti/api/TutiApiClientTest.java @@ -0,0 +1,16 @@ +package com.tuti.api; + +import static org.junit.jupiter.api.Assertions.*; + +import com.tuti.api.ebs.EBSRequest; + +import org.junit.jupiter.api.Test; + +class TutiApiClientTest { + + @Test + void quickPayment() { + EBSRequest req = new EBSRequest(); + + } +} \ No newline at end of file From 3e5f4a81144df67d2d9c88b9e139ae035d54dffc Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Sun, 21 Aug 2022 14:35:13 +0200 Subject: [PATCH 4/7] Add a constructor for ipin encryption --- lib/src/main/java/com/tuti/api/ebs/EBSRequest.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java index c5ef069..3cc1448 100644 --- a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java +++ b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.java @@ -31,8 +31,9 @@ public class EBSRequest implements Serializable { private String pubKey; - public EBSRequest(String pubKey) { + public EBSRequest(String pubKey, String ipin) { this.pubKey = pubKey; + this.IPIN = ipin; setEncryptedIPIN(pubKey); } @@ -152,7 +153,7 @@ public void setPanCategory(String panCategory) { @SerializedName("PAN") private String pan; - private String expDate, IPIN, newIPIN, originalTranUUID, otp, ipin, entityId, voucherNumber; + private String expDate, IPIN, newIPIN, originalTranUUID, otp, entityId, voucherNumber; private Float tranAmount; private String tranCurrencyCode; @@ -369,13 +370,6 @@ public void setOtp(String otp) { this.otp = otp; } - public String getIpin() { - return ipin; - } - - public void setIpin(String ipin) { - this.ipin = ipin; - } public String getPhoneNo() { return phoneNo; @@ -426,7 +420,7 @@ public void setPhoneNumber(String phoneNumber) { } public void setEncryptedIPIN(String pubKey) { - this.IPIN = getIPINBlock(ipin, pubKey, this.uuid); + this.IPIN = getIPINBlock(IPIN, pubKey, this.uuid); } private String getIPINBlock(String ipin, From f4c8c17df27d5c5cc2c20785cfbd404d6e246c39 Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Tue, 23 Aug 2022 15:37:21 +0200 Subject: [PATCH 5/7] Update card edit api --- lib/src/main/java/com/tuti/api/data/Card.java | 34 ++++--------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/lib/src/main/java/com/tuti/api/data/Card.java b/lib/src/main/java/com/tuti/api/data/Card.java index acd3f0a..c4c7502 100644 --- a/lib/src/main/java/com/tuti/api/data/Card.java +++ b/lib/src/main/java/com/tuti/api/data/Card.java @@ -10,38 +10,16 @@ public class Card { @SerializedName("pan") private String PAN; - public String getNewPan() { - return newPan; + public String getCardIndex() { + return cardIndex; } - public void setNewPan(String newPan) { - this.newPan = newPan; + public void setCardIndex(String cardIndex) { + this.cardIndex = cardIndex; } - public String getNewExpDate() { - return newExpDate; - } - - public void setNewExpDate(String newExpDate) { - this.newExpDate = newExpDate; - } - - public String getNewName() { - return newName; - } - - public void setNewName(String newName) { - this.newName = newName; - } - - // new_* are for editing_card api - @SerializedName("new_pan") - private String newPan; - @SerializedName("new_expdate") - private String newExpDate; - @SerializedName("new_name") - private String newName; - + @SerializedName("card_index") + private String cardIndex; public String getName() { return name; } From 5d89868ba0550c00005361680aa7b79a9a8aecea Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Tue, 23 Aug 2022 15:38:37 +0200 Subject: [PATCH 6/7] Read the previous pan first --- lib/src/main/java/com/tuti/api/data/Card.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/main/java/com/tuti/api/data/Card.java b/lib/src/main/java/com/tuti/api/data/Card.java index c4c7502..c632a17 100644 --- a/lib/src/main/java/com/tuti/api/data/Card.java +++ b/lib/src/main/java/com/tuti/api/data/Card.java @@ -15,6 +15,10 @@ public String getCardIndex() { } public void setCardIndex(String cardIndex) { + if (!PAN.isEmpty()) { + this.cardIndex = PAN; + return; + } this.cardIndex = cardIndex; } From 78974c5981ab84ad7d05ed1ef3be721e2fd3a67a Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Wed, 24 Aug 2022 08:54:00 +0200 Subject: [PATCH 7/7] make the card's pan index retrieved from setPan method --- lib/src/main/java/com/tuti/api/data/Card.java | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/main/java/com/tuti/api/data/Card.java b/lib/src/main/java/com/tuti/api/data/Card.java index c632a17..1d7f07f 100644 --- a/lib/src/main/java/com/tuti/api/data/Card.java +++ b/lib/src/main/java/com/tuti/api/data/Card.java @@ -46,6 +46,7 @@ public String getPAN() { public void setPAN(String PAN) { this.PAN = PAN; + this.cardIndex = PAN; } @Override