【发布时间】:2020-11-12 17:32:18
【问题描述】:
我完全按照集成paypal与Android studio的教程,但是当我点击按钮时,它并没有进入paypal,系统仍然停留在同一页面,请问是什么问题? 教程:https://www.youtube.com/watch?v=k5lPy_50f0Y&t=1068s
public class PayPal extends AppCompatActivity {
private static final int PAYPAL_REQUEST_CODE = 7171;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)
.clientId(Config.PAYPAL_CLIENT_ID);
Button btnPayNow;
EditText edtAmount;
String amount = "";
@Override
protected void onDestroy() {
stopService(new Intent(this,PayPalService.class));
super.onDestroy();}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay_pal);
Intent intent = new Intent(this,PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
startService(intent);
btnPayNow = findViewById(R.id.btnPayNow);
edtAmount = findViewById(R.id.edtAmount);
btnPayNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
processPayment();
}
});
}
private void processPayment() {
amount = edtAmount.getText().toString();
PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(String.valueOf(amount)),"RM",
"Registration Fee",PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT,payPalPayment);
startActivityForResult(intent,PAYPAL_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PAYPAL_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
PaymentConfirmation confirmation = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirmation != null) {
try {
String paymentDetails = confirmation.toJSONObject().toString(4);
startActivity(new Intent(this, PaymentDetails.class)
.putExtra("Payment Details", paymentDetails)
.putExtra("Amount", amount));
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED)
Toast.makeText(this, "Cancel", Toast.LENGTH_SHORT).show();
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
Toast.makeText(this, "Invalid", Toast.LENGTH_SHORT).show();
}
}
【问题讨论】: