我正在使用Google付费API在我的Android应用中集成Braintree,
付款对话框已经显示,在输入我点击的实时卡详细信息后继续,但onActivityResult
完全没有打电话我不知道我错过了什么,任何人都可以帮助我使用Google Pay API集成braintree
我已经提到以下链接
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPaymentsClient =
Wallet.getPaymentsClient(
getActivity(),
new Wallet.WalletOptions.Builder()
.setEnvironment(WalletConstants.ENVIRONMENT_TEST)
.build());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.create_promote, container, false);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
pay = (TextView) getView().findViewById(R.id.promote);
pay.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.promote:
if (CreatePromote.clientToken.equals("")) {
JoysaleApplication.dialog(getActivity(), getString(R.string.alert), getString(R.string.somethingwrong));
} else {
try {
mBraintreeFragment = BraintreeFragment.newInstance(getActivity(), CreatePromote.clientToken);
} catch (InvalidArgumentException e) {
e.printStackTrace();
}
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(Task<Boolean> task) {
try {
boolean result = task.getResult(ApiException.class);
if (result == true) {
PaymentDataRequest request = createPaymentDataRequest();
if (request != null) {
AutoResolveHelper.resolveTask(
mPaymentsClient.loadPaymentData(request),
getActivity(),100);
}
} else {
// Hide Google as payment option.
}
} catch (ApiException exception) {
}
}
});
}
break;
}
}
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());
PaymentMethodTokenizationParameters params =
PaymentMethodTokenizationParameters.newBuilder()
.setPaymentMethodTokenizationType(
WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY)
.addParameter("gateway","Braintree")
.addParameter("gatewayMerchantId", "replace me")
.build();
request.setPaymentMethodTokenizationParameters(params);
return request.build();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 100:
switch (resultCode) {
case Activity.RESULT_OK:
PaymentData paymentData = PaymentData.getFromIntent(data);
String token = paymentData.getPaymentMethodToken().getToken();
break;
case Activity.RESULT_CANCELED:
break;
case AutoResolveHelper.RESULT_ERROR:
Status status = AutoResolveHelper.getStatusFromIntent(data);
// Log the status for debugging.
// Generally, there is no need to show an error to
// the user as the Google Pay API will do that.
break;
default:
// Do nothing.
}
break;
default:
// Do nothing.
}
}
答案 0 :(得分:2)
在代码中添加商家ID。如下所示
addParameter(&#34; gatewayMerchantId&#34;,&#34; r3379kksdass9gt2gtjw&#34;)