首页 > 解决方案 > 找不到符号 stripe.createPaymentMethod

问题描述

当我尝试运行该应用程序时,我停留在这一点并在 Android Studio 中遇到了下一个错误。

找不到符号 stripe.createPaymentMethod()

在此处输入图像描述

所以,我想在我的应用程序中集成这个https://github.com/baranyildirim/google_pay/blob/master/android/src/main/java/com/googlepay/googlepay/GooglePayPlugin.java

但是发现这部分大部分已被弃用并且无法正常工作

case Activity.RESULT_OK:
    PaymentData paymentData = PaymentData.getFromIntent(data);
    CardInfo info = paymentData.getCardInfo();
    UserAddress address = paymentData.getShippingAddress();
    String rawToken = paymentData.getPaymentMethodToken().getToken();
    Token stripeToken = Token.fromString(rawToken);
    Map<String, Object> arguments = new LinkedHashMap<>();
    arguments.put("token", stripeToken.getId());

    if (stripeToken != null) {
        channel.invokeMethod("onGooglePaySuccess", arguments);
    }
    else {
        channel.invokeMethod("onGooglePayFailed", null);
    }

休息;

然后我决定将其替换为下一个

case Activity.RESULT_OK:
final PaymentData paymentData = PaymentData.getFromIntent(data);
if (paymentData == null) {
    channel.invokeMethod("onGooglePayFailed", null);
} else {
    final PaymentMethodCreateParams paymentMethodCreateParams =
        PaymentMethodCreateParams.createFromGooglePay(
            new JSONObject(paymentData.toJson()));

    stripe.createPaymentMethod(
        paymentMethodCreateParams,
        new ApiResultCallback<PaymentMethod>() {
            @Override
            public void onSuccess(@NonNull PaymentMethod result) {
                channel.invokeMethod("onGooglePaySuccess", result.id);
            }

            @Override
            public void onError(@NonNull Exception e) {
                channel.invokeMethod("onGooglePayFailed", null);
            }
        }
    );
}
break;

当然,我还导入了一些其他的东西,比如:

import com.stripe.android.Stripe;    
import com.stripe.android.ApiResultCallback;    
import com.stripe.android.GooglePayJsonFactory;    
import com.stripe.android.model.PaymentMethod;    
import com.stripe.android.model.PaymentMethodCreateParams;    
import com.stripe.android.PaymentConfiguration;    
import com.stripe.android.PaymentIntentResult;    
import com.stripe.android.model.PaymentIntent;    
import com.stripe.android.view.CardInputWidget;    
import androidx.annotation.NonNull;

然后我得到了上面提到的错误。AndroidManifest.xml、依赖项...等根据需要设置。

标签: javaandroidstripe-payments

解决方案


推荐阅读