【问题标题】:Android: Paypal Merchant Id error as invalid CredentialsAndroid:Paypal Merchant Id 错误作为无效凭据
【发布时间】:2014-08-08 17:48:00
【问题描述】:

我是 android 新手,使用沙盒 id 完成了 paypal 集成,但是当我使用生产环境时,它会崩溃并出现,当我检查 logcat 时,我会收到如下错误

06-18 07:09:40.221: W/DefaultRequestDirector(3943): Authentication error: Unable to respond to any of these challenges: {}
06-18 07:09:40.591: W/paypal.sdk(3943): aa SN:35 PayPal Debug-ID: 7d7a3da2bf9aa [live, 2.2.2;release]
06-18 07:09:40.591: E/paypal.sdk(3943): request failure with http statusCode:401,exception:org.apache.http.client.HttpResponseException: Unauthorized
06-18 07:09:40.641: E/paypal.sdk(3943): request failed with server response:{"error":"invalid_client","error_description":"The client credentials are invalid"}
06-18 07:09:40.641: E/PayPalService(3943): invalid_client

但是我在这个应用程序中使用的客户端 ID 是正确的,但是我在使用 生产标识。谁能告诉我为什么会发生这种情况以及 paypal SDK 是如何工作的

支付宝代码

package com.coded.sandeep;

import java.math.BigDecimal;
import java.util.StringTokenizer;

import org.json.JSONException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation; 
public class PaypalActivity extends Activity {


    private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;

    // note that these credentials will differ between live & sandbox environments.
    private static final String CONFIG_CLIENT_ID = "AfZKkxA3Detdl4CgpOKoDMUVTSn3VHq633qkQp_F5hL520589653";


    private static PayPalConfiguration config = new PayPalConfiguration()
    .environment(CONFIG_ENVIRONMENT)
    .clientId(CONFIG_CLIENT_ID);

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

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

        intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

        startActivityForResult(intent, 0);

    }

     private PayPalPayment getThingToBuy(String paymentIntent) {

        Intent intent1 = getIntent();

        String message = "people"
        String amount = "1.26"



        return new PayPalPayment(new BigDecimal(amount), "GBP", message,
                paymentIntent);

    }

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

                    Log.i("paymentExample", confirm.toJSONObject().toString(4));
                } 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.");
        }
    }

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

我正在为一个 Android 应用程序进行 Paypal 集成,但是当我使用 ENVIRONMENT_PRODUCTION 并添加我在 PayPal 中创建的实时 ID 时,我已在 Config_client_id 中添加,但添加后我的应用程序崩溃并弹出一个错误,如“商家 ID 无效”我该如何纠正这个我已经发布了我正在使用它的代码。

但是当我使用SANDBOX ENVIRONMENT 时,下面的代码工作正常,没有错误

【问题讨论】:

  • @Rutvij 你能告诉我客户 ID 有什么问题

标签: android paypal


【解决方案1】:

尝试完整代码和 sanbox Id 或客户端 Id 不同:-

    import java.io.StringReader;
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.List;

    import org.json.JSONException;
    import org.xmlpull.v1.XmlPullParser;
    import org.xmlpull.v1.XmlPullParserFactory;

    import android.app.Activity;
    import android.app.Dialog;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.Intent;
    import android.graphics.drawable.Drawable;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.text.Html;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.Window;
    import android.view.WindowManager;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ImageButton;
    import android.widget.RelativeLayout;
    import android.widget.Spinner;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.actionbarsherlock.app.ActionBar;
    import com.actionbarsherlock.app.SherlockActivity;
    import com.actionbarsherlock.view.MenuItem;
    import com.coloruapp.model.utilities.Constant;
    import com.paypal.android.sdk.payments.PayPalAuthorization;
    import com.paypal.android.sdk.payments.PayPalConfiguration;
    import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
    import com.paypal.android.sdk.payments.PayPalPayment;
    import com.paypal.android.sdk.payments.PayPalService;
    import com.paypal.android.sdk.payments.PaymentActivity;
    import com.paypal.android.sdk.payments.PaymentConfirmation;

    public class PayPalMainActivity extends Activity implements OnClickListener{

        /*
         * - Set to PaymentActivity.ENVIRONMENT_PRODUCTION to move real money.
         * 
         * - Set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials from
         * https://developer.paypal.com
         * 
         * - Set to PayPalConfiguration.ENVIRONMENT_NO_NETWORK to kick the tires without communicating
         * to PayPal's servers.
         */
        private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_PRODUCTION;

        // note that these credentials will differ between live & sandbox environments.


        private static final String CONFIG_CLIENT_ID = "Your client id";        //Live Id


        private static final int REQUEST_CODE_PAYMENT = 1;
        private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;


        private static PayPalConfiguration config;


        final Context context = this;

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


              config = new PayPalConfiguration()
             .environment(CONFIG_ENVIRONMENT)
             .clientId(CONFIG_CLIENT_ID)
             // The following are only used in PayPalFuturePaymentActivity.
             .merchantName("Your Merchent Name")
             .defaultUserEmail("Your Email id")
             .languageOrLocale("Your set Language");
             //.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
             //.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));




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


        public void onBuyPressed(View pressed) {
            // change PAYMENT_INTENT_SALE to PAYMENT_INTENT_AUTHORIZE to only authorize payment and capture funds later.
            PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(String.valueOf(1.26)), "GBP", "people",
                PayPalPayment.PAYMENT_INTENT_AUTHORIZE);

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

            intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

            startActivityForResult(intent, REQUEST_CODE_PAYMENT);
        }

        public void onFuturePaymentPressed(View pressed) {
            Intent intent = new Intent(PayPalMainActivity.this, PayPalFuturePaymentActivity.class);

            startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
        }

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


                            Toast.makeText(PayPalMainActivity.this, "Payment Successful. You will receive an email shortly", Toast.LENGTH_SHORT).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.");
                }
            } else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
                if (resultCode == Activity.RESULT_OK) {
                    PayPalAuthorization auth = data
                            .getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
                    if (auth != null) {
                        try {
                            Log.i("FuturePaymentExample", auth.toJSONObject().toString(4));

                            String authorization_code = auth.getAuthorizationCode();
                            Log.i("FuturePaymentExample", authorization_code);

                            sendAuthorizationToServer(auth);
                            Toast.makeText(getApplicationContext(), "Future Payment code received from PayPal",
                                    Toast.LENGTH_LONG).show();

                        } catch (JSONException e) {
                            Log.e("FuturePaymentExample", "an extremely unlikely failure occurred: ", e);
                        }
                    }
                } else if (resultCode == Activity.RESULT_CANCELED) {
                    Log.i("FuturePaymentExample", "The user canceled.");
                } else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
                    Log.i("FuturePaymentExample",
                            "Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
                }
            }
        }

        private void sendAuthorizationToServer(PayPalAuthorization authorization) {

            // TODO:
            // Send the authorization response to your server, where it can exchange the authorization code
            // for OAuth access and refresh tokens.
            //
            // Your server must then store these tokens, so that your server code can execute payments
            // for this user in the future.

        }

        public void onFuturePaymentPurchasePressed(View pressed) {
            // Get the Application Correlation ID from the SDK
            String correlationId = PayPalConfiguration.getApplicationCorrelationId(this);

            Log.i("FuturePaymentExample", "Application Correlation ID: " + correlationId);

            // TODO: Send correlationId and transaction details to your server for processing with
            // PayPal...
            Toast.makeText(getApplicationContext(), "App Correlation ID received from SDK",
                    Toast.LENGTH_LONG).show();
        }

        @Override
        public void onDestroy() {
            // Stop service when done
            stopService(new Intent(this, PayPalService.class));
            super.onDestroy();
        }



    }

xml代码:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#161616"
    android:orientation="vertical" >


        <ImageButton
            android:id="@+id/buyItBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:onClick="onBuyPressed" />
    </LinearLayout>



</LinearLayout>

【讨论】:

  • 一秒钟我会检查并让你知道@Rutvij
  • 这是同一件事@Rutvij 相同的错误无效客户端
  • 这篇文章被自动标记为低质量,因为它只是代码。您介意通过添加一些文本来解释它是如何解决问题的吗?
  • @gung 我一定会做到的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-02
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-07
相关资源
最近更新 更多