Skip to content

Commit

Permalink
Merge pull request #34 from processout/PROCESS0UT-960-add-thirdpartysdk
Browse files Browse the repository at this point in the history
PROCESS0UT-960: Add thirdPartySDKVersion on card verifications + incremental auth
  • Loading branch information
seb-preston-cko authored Apr 14, 2022
2 parents a4268bf + 63facf2 commit 3224e0a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public AuthorizationRequest(String source, boolean incremental) {
this.incremental = incremental;
}

public AuthorizationRequest(String source, boolean incremental, String thirdPartySDKVersion) {
this.source = source;
this.incremental = incremental;
this.thirdPartySDKVersion = thirdPartySDKVersion;
}

public AuthorizationRequest(String source) {
this.source = source;
this.incremental = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

public class ProcessOut {

public static final String SDK_VERSION = "v2.15.0";
public static final String SDK_VERSION = "v2.16.0";

private String projectId;
private Context context;
Expand Down Expand Up @@ -391,6 +391,53 @@ public void shouldContinue(String source) {
}
}

/**
* Allow card payments authorization and marks the authorization as incremental (with 3DS2 support)
*
* @param invoiceId previously generated invoice
* @param source source to use for the charge (card token, etc.)
* @param thirdPartySDKVersion version of the 3rd party SDK being used for the calls.
* @param handler (Custom 3DS2 handler)
*/
public void makeIncrementalAuthorizationPayment(@NonNull final String invoiceId, @NonNull final String source, final String thirdPartySDKVersion, @NonNull final ThreeDSHandler handler, @NonNull final Context with) {
try {
// Generate the authorization body and forces 3DS2
AuthorizationRequest authRequest = new AuthorizationRequest(source, true, thirdPartySDKVersion);
final JSONObject body = new JSONObject(gson.toJson(authRequest));

requestAuthorization(invoiceId, body, new RequestAuthorizationCallback() {
@Override
public void onError(Exception error) {
handler.onError(error);
}

@Override
public void onSuccess(JSONObject json) {
// Handle the authorization result
AuthorizationResult result = gson.fromJson(
json.toString(), AuthorizationResult.class);

CustomerAction cA = result.getCustomerAction();
if (cA == null) {
// No customer action in the authorization result, we return the invoice id
handler.onSuccess(invoiceId);
return;
}

CustomerActionHandler customerActionHandler = new CustomerActionHandler(handler, new PaymentWebView(with), with, new CustomerActionHandler.CustomerActionCallback() {
@Override
public void shouldContinue(String source) {
makeIncrementalAuthorizationPayment(invoiceId, source, handler, with);
}
});
customerActionHandler.handleCustomerAction(cA);
}
});
} catch (JSONException e) {
handler.onError(e);
}
}

/**
* Increments the authorization of an applicable invoice by a given amount
*
Expand Down Expand Up @@ -469,6 +516,54 @@ public void shouldContinue(String source) {
}
}

/**
* Create a customer token from a card ID
*
* @param source Card ID used for the customer token
* @param customerId Customer ID created in backend
* @param tokenId Token ID created in backend
* @param thirdPartySDKVersion version of the 3rd party SDK being used for the calls.
* @param handler 3DS2 handler
* @param with Activity to display webviews and perform fingerprinting
*/
public void makeCardToken(@NonNull final String source, @NonNull final String customerId, @NonNull final String tokenId, final String thirdPartySDKVersion, @NonNull final ThreeDSHandler handler, @NonNull final Context with) {
try {
TokenRequest request = new TokenRequest(source, thirdPartySDKVersion);
final JSONObject body = new JSONObject(gson.toJson(request));

Network.getInstance(this.context, this.projectId).CallProcessOut("/customers/" + customerId + "/tokens/" + tokenId, Request.Method.PUT, body, new Network.NetworkResult() {
@Override
public void onError(Exception error) {
handler.onError(error);
}

@Override
public void onSuccess(JSONObject json) {
// Handle the authorization result
AuthorizationResult result = gson.fromJson(
json.toString(), AuthorizationResult.class);

CustomerAction cA = result.getCustomerAction();
if (cA == null) {
// No customer action in the authorization result, we return the invoice id
handler.onSuccess(tokenId);
return;
}

CustomerActionHandler customerActionHandler = new CustomerActionHandler(handler, new CardTokenWebView(with), with, new CustomerActionHandler.CustomerActionCallback() {
@Override
public void shouldContinue(String source) {
makeCardToken(source, customerId, tokenId, handler, with);
}
});
customerActionHandler.handleCustomerAction(cA);
}
});
} catch (JSONException e) {
handler.onError(e);
}
}

/**
* Parses a intent uri
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ class TokenRequest {
private boolean verify = true;
@SerializedName("enable_three_d_s_2")
private boolean enableThreeDS2 = true;
@SerializedName("third_party_sdk_version")
private String thirdPartySDKVersion;

TokenRequest(String source) {
this.source = source;
}

TokenRequest(String source, String thirdPartySDKVersion) {
this.source = source;
this.thirdPartySDKVersion = thirdPartySDKVersion;
}
}

0 comments on commit 3224e0a

Please sign in to comment.