我想将Google Pay集成到我的android应用程序中。我已经尝试过this回购。出现以下错误。
该商家未启用Google付款
这是我的一些导致错误的代码。
public static final HashMap<String, String> PAYMENT_GATEWAY_TOKENIZATION_PARAMETERS = new HashMap<String, String>() {
put("gateway", "example"); // WHAT SHOULD I WIRTE INSTED OF EXAMPLE?
put("gatewayMerchantId", "MerchantIdexample"); //found from https://merchants.google.com
// Your processor may require additional parameters.
}
};
答案 0 :(得分:0)
您需要将此添加到清单(在内部应用程序中)::
<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/>
答案 1 :(得分:0)
Google pay
private PaymentsClient mPaymentsClient;
mPaymentsClient =
Wallet.getPaymentsClient(this,
new Wallet.WalletOptions.Builder()
.setEnvironment(WalletConstants.ENVIRONMENT_TEST)
.build());
private void isReadyToPay() {
messageUtil.showProgressDialog(this);
IsReadyToPayRequest request = IsReadyToPayRequest.newBuilder()
.addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_CARD)
.addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD)
.build();
Task<Boolean> task = mPaymentsClient.isReadyToPay(request);
task.addOnCompleteListener(
new OnCompleteListener<Boolean>() {
public void onComplete(@NonNull Task<Boolean> task) {
messageUtil.hideProgressDialog();
try {
boolean result =
task.getResult(ApiException.class);
if(result) {
Toast.makeText(getApplicationContext(), "Ready", Toast.LENGTH_SHORT).show();
payWithGoogle();
} else {
Toast.makeText(getApplicationContext(), "No PWG", Toast.LENGTH_SHORT).show();
//hide Google as payment option
}
} catch (ApiException exception) {
Toast.makeText(getApplicationContext(),
"Exception: " + exception.getLocalizedMessage(),
Toast.LENGTH_LONG).show();
}
}
});
}
private void payWithGoogle() {
PaymentDataRequest request = createPaymentDataRequest();
if (request != null) {
AutoResolveHelper.resolveTask(
mPaymentsClient.loadPaymentData(request),
this,
LOAD_PAYMENT_DATA_REQUEST_CODE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case LOAD_PAYMENT_DATA_REQUEST_CODE:
switch (resultCode) {
case Activity.RESULT_OK:
PaymentData paymentData = PaymentData.getFromIntent(data);
// You can get some data on the user's card, such as the brand and last 4 digits
CardInfo info = paymentData.getCardInfo();
// You can also pull the user address from the PaymentData object.
UserAddress address = paymentData.getShippingAddress();
// This is the raw string version of your Stripe token.
String rawToken = paymentData.getPaymentMethodToken().getToken();
// Now that you have a Stripe token object, charge that by using the id
Token stripeToken = Token.fromString(rawToken);
if (stripeToken != null) {
// This chargeToken function is a call to your own server, which should then connect
// to Stripe's API to finish the charge.
// chargeToken(stripeToken.getId());
Toast.makeText(getApplicationContext(),
"Got token " + stripeToken.toString(), Toast.LENGTH_LONG).show();
}
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getApplicationContext(),
"Canceled", Toast.LENGTH_LONG).show();
break;
case AutoResolveHelper.RESULT_ERROR:
Status status = AutoResolveHelper.getStatusFromIntent(data);
Toast.makeText(getApplicationContext(),
"Got error " + status.getStatusMessage(), Toast.LENGTH_SHORT).show();
// Log the status for debugging
// Generally there is no need to show an error to
// the user as the Google Payment API will do that
break;
default:
// Do nothing.
}
break; // Breaks the case LOAD_PAYMENT_DATA_REQUEST_CODE
default:
// Do nothing.
}
}
private PaymentMethodTokenizationParameters createTokenizationParameters() {
return PaymentMethodTokenizationParameters.newBuilder()
.setPaymentMethodTokenizationType(WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY)
.addParameter("gateway", "stripe")
.addParameter("stripe:publishableKey",
Constants.STRIPE_KEY)
.addParameter("stripe:version", "2018-11-08")
.build();
}
private PaymentDataRequest createPaymentDataRequest() {
PaymentDataRequest.Builder request =
PaymentDataRequest.newBuilder()
.setTransactionInfo(
TransactionInfo.newBuilder()
.setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
.setTotalPrice("10.00")
.setCurrencyCode("USD")
.build())
.addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_CARD)
.addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD)
.setCardRequirements(
CardRequirements.newBuilder()
.addAllowedCardNetworks(Arrays.asList(
WalletConstants.CARD_NETWORK_AMEX,
WalletConstants.CARD_NETWORK_DISCOVER,
WalletConstants.CARD_NETWORK_VISA,
WalletConstants.CARD_NETWORK_MASTERCARD))
.build());
request.setPaymentMethodTokenizationParameters(createTokenizationParameters());
return request.build();
}
答案 2 :(得分:-1)
交易可能有风险。为了您的安全,此时无法完成我在使用此代码时也收到此错误
</a>