我想在我的android应用程序中实现Google pay,并且希望BlueSnap
作为Google Pay
处理器。我已经在May应用程序中实现了Google Pay
,并且还创建了BlueSnap
沙箱帐户。输入我的实时卡详细信息时,我会收到此吐司成功接收付款数据。我还在GatewayMerchantId
中的网关和沙箱商人ID中编写了bluesnap。现在我被困住了,有人可以帮助我如何将付款数据发送到BlueSnap
并从BlueSnap
获取付款确认,以便我的付款显示在BlueSnap
沙箱仪表板上。
谢谢。
我已将我的handlePaymentSuccess()
代码上传到我要接收吐司的地方,并且将gatewatTokenization()
方法上传到了我编写网关和商人ID的地方。如果您需要更多代码,可以上传。
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's documentation:
此paymentToken
应该发送到BlueSnap API,这在Processing Transactions部分中进行了详细说明。
我认为相关的部分是使用您作为paymentToken
的一部分收到的createBlsTokenFromGooglePayPaymentData
向BlueSnap发出HTTP POST:
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
的值。