简体   繁体   English

贝宝付款Android

[英]Paypal payment android

I am trying integrate paypal with my android application but I am getting and error paypal android error_description":"Invalid client_id" As it clearly saying Client_id is invalid but I can't see any mistake I just copied from this page. ![enter image description here][1] 我正在尝试将Paypal与我的android应用程序集成在一起,但我却遇到了错误paypal android error_description":"Invalid client_id"因为它清楚地表明Client_id无效,但是我看不到我刚刚从此页面复制的任何错误。这里的描述] [1]

Code look like this 代码看起来像这样

public class MainActivity extends Activity implements OnClickListener{

private Button btnPay;
//set the environment for production/sandbox/no netowrk
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;

private static final String CONFIG_CLIENT_ID = "nsdkjansdknaskd7415150U";

private static final int REQUEST_PAYPAL_PAYMENT = 1;

private static PayPalConfiguration config = new PayPalConfiguration()
        .environment(CONFIG_ENVIRONMENT)
        .clientId(CONFIG_CLIENT_ID)
        // The following are only used in PayPalFuturePaymentActivity.
        .merchantName("Android Hub 4 You")
        .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
        .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btnPay=(Button)findViewById(R.id.button1);
    btnPay.setOnClickListener(this);

    /**
     * call pay pal services
     */

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



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.button1 :
         PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(1),"USD", "androidhub4you.com",
                    PayPalPayment.PAYMENT_INTENT_SALE);

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

                intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

                startActivityForResult(intent, REQUEST_PAYPAL_PAYMENT); 
        break;
    }

}

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_PAYPAL_PAYMENT) {
            if (resultCode == Activity.RESULT_OK) {
                PaymentConfirmation confirm = data
                        .getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
                if (confirm != null) {
                    try {
                        System.out.println("Responseeee"+confirm);
                        Log.i("paymentExample", confirm.toJSONObject().toString());


                        JSONObject jsonObj=new JSONObject(confirm.toJSONObject().toString());

                        String paymentId=jsonObj.getJSONObject("response").getString("id");
                        System.out.println("payment id:-=="+paymentId);
                        Toast.makeText(getApplicationContext(), paymentId, Toast.LENGTH_LONG).show();  

                    } catch (JSONException e) {
                        Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                    }
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                Log.i("paymentExample", "The user canceled.");
            } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
                Log.i("paymentExample", "An invalid Payment was submitted. Please see the docs.");
            }
        } 


  }




  }

You are not using the correct credentials. 您没有使用正确的凭据。 The 'App ID' that you are currently using are for the PayPal Adaptive Payment APIs and the legacy MPL. 您当前使用的“应用程序ID”用于PayPal自适应支付API和旧版MPL。 For the Android mSDK, you'll need to follow the instructions here to create a REST API app. 对于Android mSDK,您需要按照此处的说明创建REST API应用。 This will show you how to create an App on the developer portal so that you are provided with a Client ID and secret. 这将向您展示如何在开发人员门户上创建应用程序,以便为您提供客户端ID和密码。 This Client ID is what you need to use in the Android mSDK code you have above. 您需要在上面的Android mSDK代码中使用此客户端ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM