首页 文章

PAYTM与我的APP集成

提问于
浏览
1

我是Android新手 . 我被要求将paytm整合到客户应用程序中 . 我按照这里给出的步骤:

https://www.simplifiedcoding.net/paytm-integration-android-example/

我收到一个奇怪的错误,不知道如何解决这个问题,我也从上面的网站下载了源代码,它给了我同样的错误 .

06-20 20:04:07.575 24839-24839/simplifiedcoding.net.paytmpaymentsample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: simplifiedcoding.net.paytmpaymentsample, PID: 24839
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String simplifiedcoding.net.paytmpaymentsample.Checksum.getChecksumHash()' on a null object reference
        at simplifiedcoding.net.paytmpaymentsample.MainActivity$2.onResponse(MainActivity.java:95)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6753)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
06-20 20:04:07.592 24839-25361/simplifiedcoding.net.paytmpaymentsample D/OSTracker: OS Event: crash
06-20 20:04:07.666 24839-25361/simplifiedcoding.net.paytmpaymentsample D/AbstractTracker: Event success

这是使用的代码:

String txnAmount = textViewPrice.getText().toString().trim();

        //creating a retrofit object.
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Api.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        //creating the retrofit api service
        Api apiService = retrofit.create(Api.class);

        //creating paytm object
        //containing all the values required
        final Paytm paytm = new Paytm(
                Constants.M_ID,
                Constants.CHANNEL_ID,
                txnAmount,
                Constants.WEBSITE,
                Constants.CALLBACK_URL,
                Constants.INDUSTRY_TYPE_ID
        );

        //creating a call object from the apiService
        Call<Checksum> call = apiService.getChecksum(
                paytm.getmId(),
                paytm.getOrderId(),
                paytm.getCustId(),
                paytm.getChannelId(),
                paytm.getTxnAmount(),
                paytm.getWebsite(),
                paytm.getCallBackUrl(),
                paytm.getIndustryTypeId()
        );

        //making the call to generate checksum
        call.enqueue(new Callback<Checksum>() {
            @Override
            public void onResponse(Call<Checksum> call, Response<Checksum> response) {

                //once we get the checksum we will initiailize the payment.
                //the method is taking the checksum we got and the paytm object as the parameter

 **I am getting an error from below line:**

                initializePaytmPayment(response.body().getChecksumHash(), paytm);
            }

            @Override
            public void onFailure(Call<Checksum> call, Throwable t) {

            }
        });

怎么了?

1 回答

  • 0

    根据错误日志,您的apiService变量为null,并且您尝试在其上调用方法(getChecksum) . 将调试指针放在您声明apiService变量的行上,并检查其值为null . 如果它为null,请尝试找出原因 . 最可能的外部api就像paytm需要OAuth验证,你可能错过了 .

相关问题