在Android SDK的Stripe AddPaymentMethodActivity中找不到生成器符号



我在尝试从stripe Android SDK加载条带活动时遇到一个构建错误。

import androidx.appcompat.app.AppCompatActivity;
import com.stripe.android.PaymentSession;
import com.stripe.android.PaymentSessionConfig;
import com.stripe.android.PaymentSessionData;
import com.stripe.android.view.AddPaymentMethodActivityStarter;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import android.os.Bundle;
import android.content.Intent;
public class HostActivity extends AppCompatActivity {
private PaymentSession paymentSession;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
paymentSession = new PaymentSession(
this,
createPaymentSessionConfig()
);
paymentSession.init(createPaymentSessionListener());
}

private void launchPaymentMethodsActivity() {
new AddPaymentMethodActivityStarter(this).startForResult(
AddPaymentMethodActivityStarter.Args.Builder()
.setShouldAttachToCustomer(true)
.setShouldRequirePostalCode(true)
.build()
);
}
@NonNull
private PaymentSession.PaymentSessionListener createPaymentSessionListener() {
return new PaymentSession.PaymentSessionListener() {
@Override
public void onCommunicatingStateChanged(
boolean isCommunicating
) {
// update UI, such as hiding or showing a progress bar
}
@Override
public void onError(
int errorCode,
@NonNull String errorMessage
) {
// handle error
}
@Override
public void onPaymentSessionDataChanged(
@NonNull PaymentSessionData data
) {
data.getPaymentMethod();
}
};
}
@NonNull
private PaymentSessionConfig createPaymentSessionConfig() {
return new PaymentSessionConfig.Builder()
.build();
}
}

由此产生的错误是

error: cannot find symbol
AddPaymentMethodActivityStarter.Args.Builder()
^
symbol:   method Builder()
location: class Args

startForResult需要";com.stripe.android.view.AddPaymentMethodActivityStarter.Args";作为输入,Stripe的Docs说";活动可以用Args指定并用Args.Builder构造;但是类似于其他在线示例,在引用时似乎找不到Builder((构造函数。

我已经初始化了客户会话,我只想打开Stripe Activity来添加新的支付方式。启动AddPaymentMethodActivity的正确方法是什么?

解决方案是缺少"新的";关键字。将launchPaymentMethods Activity方法更新为以下内容解决了问题。

private void launchPaymentMethodsActivity() {
new AddPaymentMethodActivityStarter(this).startForResult(
new AddPaymentMethodActivityStarter.Args.Builder()
.setShouldAttachToCustomer(true)
.setShouldRequirePostalCode(true)
.build()
);
}

最新更新