3

I want to implement Google pay in my android application and I want BlueSnap as Google Pay processor. I have implemented Google Pay in may app and have also created BlueSnap sandbox account. When I enter my live card details i receive this toast Successfully received payment data. I have also written bluesnap in gateway and sandbox merchant id in GatewayMerchantId. Now I am stuck, can someone help me out on how to send this payment data to BlueSnap and get payment confirmation from BlueSnap so that my payment would show on BlueSnap sandbox dashboard.

Thank you.

I have uploaded my handlePaymentSuccess() code where I am receiving toast and gatewatTokenization() method where I have written gateway and merchantId. If you need more code, I can upload it.

private void handlePaymentSuccess(PaymentData paymentData) {

        String paymentInformation = paymentData.toJson();

        // Token will be null if PaymentDataRequest was not constructed using fromJson(String).
        if (paymentInformation == null) {
            return;
        }
        JSONObject paymentMethodData;

        try {

            paymentMethodData = new JSONObject(paymentInformation).getJSONObject("paymentMethodData");
            // If the gateway is set to "example", no payment information is returned - instead, the
            // token will only consist of "examplePaymentMethodToken".
            if (paymentMethodData
                    .getJSONObject("tokenizationData")
                    .getString("type")
                    .equals("PAYMENT_GATEWAY")
                    && paymentMethodData
                    .getJSONObject("tokenizationData")
                    .getString("token")
                    .equals("examplePaymentMethodToken")) {
                android.app.AlertDialog alertDialog =
                        new android.app.AlertDialog.Builder(this)
                                .setTitle("Warning")
                                .setMessage(
                                        "Gateway name set to \"example\" - please modify "
                                                + "Constants.java and replace it with your own gateway.")
                                .setPositiveButton("OK", null)
                                .create();
                alertDialog.show();
            }

            String billingName =
                    paymentMethodData.getJSONObject("info").getJSONObject("billingAddress").getString("name");

            JSONObject testing =
                    paymentMethodData.getJSONObject("info");

            JSONObject testingNew =
                    paymentMethodData;

            try {
                String paymentToken = createBlsTokenFromGooglePayPaymentData(paymentData);
                //Toast.makeText(this, String.valueOf(paymentToken), Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                e.printStackTrace();
            }

            Log.d("BillingName", billingName);
            Toast.makeText(this, getString(R.string.payments_show_name, billingName), Toast.LENGTH_LONG).show();
            //Toast.makeText(this, String.valueOf(testing), Toast.LENGTH_LONG).show();


            // Logging token string.
            Log.d("GooglePaymentToken", paymentMethodData.getJSONObject("tokenizationData").getString("token"));
        } catch (JSONException e) {
            Log.e("handlePaymentSuccess", "Error: " + e.toString());
            return;
        }
    }
private static JSONObject getGatewayTokenizationSpecification() throws JSONException {
    return new JSONObject(){{
      put("type", "PAYMENT_GATEWAY");
      put("parameters", new JSONObject(){{
        put("gateway", "bluesnap");
        put("gatewayMerchantId", "######");//i've hidden MerchantId
        }
      });
    }};
  }
Dinesh Shingadiya
  • 988
  • 1
  • 8
  • 23
Asad Alii
  • 31
  • 5

1 Answers1

0

According to BlueSnap's documentation:

This paymentToken should be sent to the BlueSnap API, which is detailed in the Processing Transactions section.

I think the relevant piece is to issue a HTTP POST to BlueSnap with the paymentToken that you received as part of createBlsTokenFromGooglePayPaymentData:

curl -v -X POST https://sandbox.bluesnap.com/services/2/transactions \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \ 
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
-d '
{
    "cardTransactionType": "AUTH_CAPTURE",
    "softDescriptor": "DescTest",
    "amount": 11.00,
    "currency": "USD",
    "wallet": {
      "walletType": "GOOGLE_PAY",
      "encodedPaymentToken": "ImRhdGEiOiJuY1AvRitIUy8zeG5bXhCMFd"
    }
}

Where paymentToken is assigned to the value of encodedPaymentToken.

Soc
  • 7,425
  • 4
  • 13
  • 30