Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/java/com/xfers/model/Connect.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Connect {
public static ConnectResponse getToken(String phoneNumber, String OTP, String returnURL, String appKey, String secretKey)
throws AuthenticationException, InvalidRequestException, APIException, APIConnectionException, UnirestException {
Map<String, Object> params = new HashMap<String, Object>();
phoneNumber = validate_phone(phoneNumber);
params.put("phone_no", phoneNumber);
params.put("otp", OTP);
params.put("signature", getSignature(phoneNumber, secretKey, OTP));
Expand All @@ -44,6 +45,7 @@ public static ConnectResponse getToken(String phoneNumber, String OTP, String re
public static String authorize(String phoneNumber, String appKey, String secretKey)
throws AuthenticationException, InvalidRequestException, APIException, APIConnectionException, UnirestException {
Map<String, Object> params = new HashMap<String, Object>();
phoneNumber = validate_phone(phoneNumber);
params.put("phone_no", phoneNumber);
params.put("signature", getSignature(phoneNumber, secretKey));

Expand All @@ -59,6 +61,7 @@ public static String authorize(String phoneNumber, String appKey, String secretK
public static ConnectResponse privateAuthorize(String phoneNumber, String appKey, String secretKey)
throws AuthenticationException, InvalidRequestException, APIException, APIConnectionException, UnirestException {
Map<String, Object> params = new HashMap<String, Object>();
phoneNumber = validate_phone(phoneNumber);
params.put("phone_no", phoneNumber);
params.put("signature", getSignature(phoneNumber, secretKey));

Expand Down Expand Up @@ -93,7 +96,16 @@ public static String validate_phone(String phoneNumber)
{
if(phoneNumber.charAt(0) == '0')
{
return "+62".concat(phoneNumber.substring(1));
phoneNumber = phoneNumber.replaceFirst("^0+(?!$)", "");
if (phoneNumber.charAt(0) == '6' && phoneNumber.charAt(1) == '2')
{
return "+".concat(phoneNumber);
}
return "+62".concat(phoneNumber);
}
else if(phoneNumber.charAt(0) == '6' && phoneNumber.charAt(1) == '2')
{
return "+".concat(phoneNumber);
}
else
{
Expand All @@ -102,6 +114,7 @@ public static String validate_phone(String phoneNumber)
}

}

public static String getSignature(String phoneNumber, String secretKey, String OTP) {
String beforeSHA1;
phoneNumber = validate_phone(phoneNumber);
Expand Down