Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tutipay/java-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
adonese committed Aug 25, 2022
2 parents 07245f0 + 78974c5 commit 40b71a6
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 39 deletions.
4 changes: 2 additions & 2 deletions lib/src/main/java/com/tuti/api/TutiApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public void getPaymentToken(String uuid, ResponseCallable<TutiResponse> onRespon
sendRequest(RequestMethods.GET, serverURL + Operations.GetPaymentToken, null, TutiResponse.class, TutiResponse.class, onResponse, onError, null, "uuid", uuid);
}

public void quickPayment(EBSRequest request, ResponseCallable<PaymentToken> onResponse, ErrorCallable<TutiResponse> onError) {
sendRequest(RequestMethods.POST, serverURL + Operations.QuickPayment, request, TutiResponse.class, TutiResponse.class, onResponse, onError, null);
public void quickPayment(EBSRequest request, ResponseCallable<PaymentToken> onResponse, ErrorCallable<PaymentToken> 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<String, String> headers, String ...params) {
Expand Down
39 changes: 11 additions & 28 deletions lib/src/main/java/com/tuti/api/data/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,20 @@ 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) {
if (!PAN.isEmpty()) {
this.cardIndex = PAN;
return;
}
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;
}
Expand All @@ -64,6 +46,7 @@ public String getPAN() {

public void setPAN(String PAN) {
this.PAN = PAN;
this.cardIndex = PAN;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/java/com/tuti/api/data/PaymentToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void setCardTobePaid(String cardTobePaid) {

@SerializedName("toCard")
private String cardTobePaid;

private EBSResponse transaction;

@SerializedName("is_paid")
Expand Down
92 changes: 84 additions & 8 deletions lib/src/main/java/com/tuti/api/ebs/EBSRequest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
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;
import java.util.List;
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")
private final String uuid = generateUUID();
private final String tranDateTime = getDate();
private final String applicationId = "TutiPay";

private String pubKey;

public EBSRequest(String pubKey, String ipin) {
this.pubKey = pubKey;
this.IPIN = ipin;
setEncryptedIPIN(pubKey);
}

public EBSRequest() {

}

public String getAuthenticationType() {
return authenticationType;
}
Expand Down Expand Up @@ -129,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;

Expand Down Expand Up @@ -183,6 +207,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;
}
Expand Down Expand Up @@ -342,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;
Expand Down Expand Up @@ -397,6 +418,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;
}

}


7 changes: 6 additions & 1 deletion lib/src/test/java/com/tuti/api/TutiApiClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import static org.junit.jupiter.api.Assertions.*;

import com.tuti.api.ebs.EBSRequest;

import org.junit.jupiter.api.Test;


import java.util.UUID;

class TutiApiClientTest {
Expand All @@ -13,6 +16,8 @@ void getPaymentToken() {
TutiApiClient tutiApiClient = new TutiApiClient();
UUID uuid = UUID.randomUUID();
tutiApiClient.getPaymentToken(uuid.toString(),null, null );
void quickPayment() {
EBSRequest req = new EBSRequest();

}
}
}

0 comments on commit 40b71a6

Please sign in to comment.