Skip to content

Commit

Permalink
Fix Samsung Pay error.
Browse files Browse the repository at this point in the history
  • Loading branch information
sshropshire committed Feb 7, 2023
1 parent 6f8005b commit dca0e86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.braintreepayments.api;

import android.os.Parcel;
import android.text.TextUtils;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -36,7 +37,12 @@ static SamsungPayNonce fromJSON(JSONObject inputJson) throws JSONException {

JSONObject details = paymentMethod.getJSONObject("details");
String cardType = details.getString("brand");
String last4 = details.getString("last4");

String last4 = details.optString("last4");
if (TextUtils.isEmpty(last4)) {
// fallback to source card last 4; throws when fallback not present
last4 = details.getString("sourceCardLast4");
}

// This is a hack to get around the mismatch between the GraphQL API version used in
// the Braintree Android SDK and the API version used by Samsung to tokenize. Samsung's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class SamsungPayNonceUnitTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ object Fixtures {
// language=JSON
const val SAMSUNG_PAY_RESPONSE_V1 = """
{
"data": "{\n \"data\": {\n \"tokenizeSamsungPayCard\": {\n \"singleUseToken\": {\n \"id\": \"tokensam_bf_v8s9hv_2htw4m_nh4f45_y3hsft_wty\",\n \"details\": {\n \"brand\": \"Mastercard\",\n \"brandCode\": \"MASTERCARD\",\n \"last4\": \"1798\",\n \"expirationYear\": \"2020\",\n \"expirationMonth\": \"12\",\n \"binData\": {\n \"commercial\": \"UNKNOWN\",\n \"countryOfIssuance\": \"US\",\n \"debit\": \"NO\",\n \"durbinRegulated\": \"UNKNOWN\",\n \"healthcare\": \"YES\",\n \"issuingBank\": null,\n \"payroll\": \"UNKNOWN\",\n \"prepaid\": \"UNKNOWN\",\n \"productId\": \"123\"\n },\n \"origin\": {\n \"type\": \"SAMSUNG_PAY\",\n \"details\": {\n \"bin\": \"411111\"\n }\n }\n }\n }\n }\n },\n \"extensions\": {\n \"requestId\": \"9eaf90d9-4e8a-4883-96c4-01c02bb0a4e5\"\n }\n}",
"data": "{\n \"data\": {\n \"tokenizeSamsungPayCard\": {\n \"singleUseToken\": {\n \"id\": \"tokensam_bf_v8s9hv_2htw4m_nh4f45_y3hsft_wty\",\n \"details\": {\n \"brand\": \"Mastercard\",\n \"brandCode\": \"MASTERCARD\",\n \"sourceCardLast4\": \"1798\",\n \"expirationYear\": \"2020\",\n \"expirationMonth\": \"12\",\n \"binData\": {\n \"commercial\": \"UNKNOWN\",\n \"countryOfIssuance\": \"US\",\n \"debit\": \"NO\",\n \"durbinRegulated\": \"UNKNOWN\",\n \"healthcare\": \"YES\",\n \"issuingBank\": null,\n \"payroll\": \"UNKNOWN\",\n \"prepaid\": \"UNKNOWN\",\n \"productId\": \"123\"\n },\n \"origin\": {\n \"type\": \"SAMSUNG_PAY\",\n \"details\": {\n \"bin\": \"411111\"\n }\n }\n }\n }\n }\n },\n \"extensions\": {\n \"requestId\": \"9eaf90d9-4e8a-4883-96c4-01c02bb0a4e5\"\n }\n}",
"reference":"tokensam_bf_v8s9hv_2htw4m_nh4f45_y3hsft_wty",
"status":"AUTHORIZED",
"payment_last4_dpan":"1798",
Expand Down

0 comments on commit dca0e86

Please sign in to comment.