我想在我的Android应用程序中实现Google Pay,并且我希望BlueSnap
作为Google Pay
处理器。我在5月应用程序中实现了Google Pay
,还创建了BlueSnap
沙箱帐户。当我输入实时卡详细信息时,我会收到此Toast 成功收到的付款数据。我还在GatewayMerchantId
中的网关和沙盒商户ID中写了 BluesNap 。现在我被卡住了,有人可以帮助我如何将此付款数据发送给BlueSnap
并从BlueSnap
获得付款确认,以便我的付款将在BlueSnap
Sandbox仪表板上显示。
谢谢。
我上传了我的handlePaymentSuccess()
代码,在其中我收到吐司和gatewatTokenization()
方法,其中写了网关和商品。如果您需要更多代码,我可以上传。
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
}
});
}};
}
根据BluesNap的文档:
该
paymentToken
应发送到BluesNap API,该API在"处理交易"部分中详细介绍。
我认为相关的作品是将HTTP帖子发布给您作为createBlsTokenFromGooglePayPaymentData
的一部分而收到的paymentToken
:
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" } }
其中paymentToken
分配给encodedPaymentToken
的值。