gpt4 book ai didi

android - PaymentActivity.EXTRA_PAYMENT 无效

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:36 25 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,我尝试创建一个连接到 paypal 的按钮来获得一些谢谢你的钱 :),由于规定,我不使用捐赠。无论如何,我尝试使用 PayPal-Android-SDK ( https://github.com/paypal/PayPal-Android-SDK ),当我使用 ENV_NONE、ENV_SANDBOX、ENV_LIVE 时,我总是在 Logcat 中收到错误:PaymentActivity.EXTRA_PAYMENT 无效。

我使用下面的代码

protected void onCreate(Bundle savedInstanceState) {
...
Intent intent = new Intent(this, PayPalService.class);

intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
initLibrary();
showPayPalButton();
}

public void initLibrary() {
PayPal pp = PayPal.getInstance();
if (pp == null) { // Test to see if the library is already initialized
// This main initialization call takes your Context, AppID, and target server
pp = PayPal.initWithAppID(this,"<mycode/deleted from post>", PayPal.ENV_NONE);
// Required settings:
// Set the language for the library
pp.setLanguage("en_US");
// Some Optional settings:
// Sets who pays any transaction fees. Possible values are:
// FEEPAYER_SENDER, FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and FEEPAYER_SECONDARYONLY
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// true = transaction requires shipping
pp.setShippingEnabled(true);
_paypalLibraryInit = true;
}
}


private void showPayPalButton() {
// Generate the PayPal checkout button and save it for later use
PayPal pp = PayPal.getInstance();
launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
// The OnClick listener for the checkout button
launchPayPalButton.setOnClickListener(this);

// Add the listener to the layout
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams (LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.bottomMargin = 10;
launchPayPalButton.setLayoutParams(params);
launchPayPalButton.setId(PAYPAL_BUTTON_ID);
((LinearLayout) findViewById(R.id.insert_expense_layout)).addView(launchPayPalButton);
((LinearLayout) findViewById(R.id.insert_expense_layout)).setGravity(Gravity.CENTER_HORIZONTAL);
}

public void PayPalButtonClick(View arg0) {

// Create a basic PayPal payment
PayPalPayment payment = new PayPalPayment();

// Set the currency type
payment.setCurrencyType("USD");

// Set the recipient for the payment (can be a phone number)

// Set the payment amount, excluding tax and shipping costs
payment.setSubtotal(new BigDecimal(1));

Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
//intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, ""); //with this line uncommented it also fails
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);

}

public void PayPalActivityResult(int requestCode, int resultCode, Intent intent) {
....
}

@Override
public void onClick(View v) {
PayPalButtonClick(v);
}

我没有想法,我没有在文档中找到任何有用的东西..

提前感谢您的帮助!

最佳答案

请检查您导入的付款类别是否正确:

com.paypal.android.sdk.payments.PayPalPayment

SampleApp显示应如何实例化此类:

PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("1.75"), "USD", "时髦牛仔裤");

关于android - PaymentActivity.EXTRA_PAYMENT 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21367396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com