gpt4 book ai didi

android - 适用于 Android 的 Paypal 沙盒集成

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

我使用 android paypal sdk 进行 paypal 集成,我使用这段代码

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);


startService(intent);

}

public void onBuyPressed(View pressed) {
PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);

Intent intent = new Intent(MainActivity.this, PaymentActivity.class);

intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

startActivityForResult(intent, REQUEST_CODE_PAYMENT);

}

我收到这样的错误,例如此请求因服务器响应而失败:

{"name":"TRANSACTION_REFUSED","message":"The request was refused.{0}","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#TRANSACTION_REFUSED","debug_id":"f1123aecd0ece"}
05-15 13:36:53.530: E/PayPalService(9581): TRANSACTION_REFUSED

谁能帮帮我

最佳答案

public class PaymentConfermationFragment extends Fragment {
private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_SANDBOX;
private static final String CONFIG_CLIENT_ID = "ASdSlRC8iBoCu6ehg59npQXZfhfhfhfhfhl6xQVx0IcYKCCUrZNfcdTBI0zdYCroY1ONz";
private static final String CONFIG_RECEIVER_EMAIL = "xyz@gmail.com";

private FragmentManager mFragmentManager;
private TextView frind_name, amount;
private ImageView frind_img;

private GiftekFriend giftekFriend;
private ArrayList<GiftekProduct> productList;

private View mLoadingCover;
private View mPaymentOK;

long price = 0;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.frag_payment_confirmation, container, false);

frind_img = (ImageView) rootView.findViewById(R.id.friend_img);
frind_name = (TextView) rootView.findViewById(R.id.friend_name);

mLoadingCover = rootView.findViewById(R.id.loading_cover);
mPaymentOK = rootView.findViewById(R.id.payment_ok);

amount = (TextView) rootView.findViewById(R.id.amount);

((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("Payment");

giftekFriend = AppData.getInstance().getGiftekFriend();
if (giftekFriend != null) {
String name = giftekFriend.first_name + " " + giftekFriend.last_name;
frind_name.setText(name);
}

productList = AppData.getInstance().getProductList();

Intent intent = new Intent(this.getActivity(), 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);
getActivity().startService(intent);

rootView.findViewById(R.id.payment_button).setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
paymentStart();
}
});
new Imageloder().execute();
mFragmentManager = getActivity().getSupportFragmentManager();

return rootView;
}

protected void paymentStart() {

PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(Integer.parseInt(amount.getText().toString())), "USD", "Giftek Gifts");

Intent intent = new Intent(this.getActivity(), PaymentActivity.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);

intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "credential-from-developer.paypal.com");
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "your-customer-id-in-your-system");
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

startActivityForResult(intent, 0);

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

onPaymentSuccess();
if (confirm != null) {
try {
System.out.print(confirm.toJSONObject().toString(4));
Log.i("paymentExample", confirm.toJSONObject().toString(3));
Log.i("paymentExample", confirm.toJSONObject().toString(2));
Log.i("paymentExample", confirm.toJSONObject().toString(1));
Log.i("paymentExample", confirm.toJSONObject().toString(0));
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
onPaymentCancel();
Log.i("paymentExample", "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
onPaymentInvalid();
Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
}
}

private void onPaymentInvalid() {
Bundle args = new Bundle();
args.putString("result", "Payment Invalid");

mFragmentManager.popBackStack("giftek-process-select-friend", 0);
mFragmentManager.beginTransaction()
.replace(R.id.container, ResultFragment.instantiate(getActivity(), ResultFragment.class.getName(), args))
.addToBackStack("result").commit();
}

private void onPaymentCancel() {
Bundle args = new Bundle();
args.putString("result", "Payment Cancel");

mFragmentManager.popBackStack("giftek-process-select-friend", 0);
mFragmentManager.beginTransaction()
.replace(R.id.container, ResultFragment.instantiate(getActivity(), ResultFragment.class.getName(), args))
.addToBackStack("result").commit();
}

private void onPaymentSuccess() {
Bundle args = new Bundle();
args.putString("result", "Order has been completed successfully.");

mFragmentManager.popBackStack("giftek-process-select-friend", 0);
mFragmentManager.beginTransaction()
.replace(R.id.container, ResultFragment.instantiate(getActivity(), ResultFragment.class.getName(), args))
.addToBackStack("result").commit();
}

@Override
public void onDestroy() {
getActivity().stopService(new Intent(getActivity(), PayPalService.class));
super.onDestroy();
}

关于android - 适用于 Android 的 Paypal 沙盒集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23674902/

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