I am integrating paytm all in one sdk in android and i am getting a success code everytime but the body is null in android

huangapple go评论80阅读模式
英文:

I am integrating paytm all in one sdk in android and i am getting a success code everytime but the body is null in android

问题

这是用于APIInterface的代码:

@Multipart
@POST("paytm")
@Headers({"Content-Type: application/json;charset=UTF-8"})
Call<Token_Res> generateTokenCall(
        @HeaderMap Map<String, String> header,
        @Part("code") RequestBody language,
        @Part("MID") RequestBody mid,
        @Part("ORDER_ID") RequestBody order_id,
        @Part("AMOUNT") RequestBody amount
);

这是我的Retrofit类:

package com.csk.jagdishshop.paytm;

import com.csk.jagdishshop.BuildConfig;
import com.csk.jagdishshop.NullOnEmptyConverterFactory;
import com.csk.jagdishshop.retrofit.APIService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ServiceWrapper {
    // ...(略去其余代码)
}

这是网络调用活动部分:

private void getToken() {
    // ...(略去其余代码)
}

public void startPaytmPayment(String token) {
    // ...(略去其余代码)
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // ...(略去其余代码)
}

这是Logcat输出:

D/OkHttp: --> POST https://jagdishshop.com/api/paytm http/1.1
D/OkHttp: Content-Type: application/json;charset=UTF-8
D/OkHttp: Content-Length: 816
D/OkHttp: Authorization: Bearer ...
D/OkHttp: X-Requested-With: XMLHttpRequest
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name="code"
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 5
D/OkHttp: 12345
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name="MID"
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 20
D/OkHttp: QKBnVxxxxxxxxx65
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name="ORDER_ID"
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 4
D/OkHttp: 8361
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name="AMOUNT"
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 3
D/OkHttp: 100
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda--
D/OkHttp: --> END POST (816-byte body)

D/OkHttp: <-- 200 OK https://jagdishshop.com/api/paytm (329ms)
D/OkHttp: Date: Tue, 15 Sep 2020 05:53:09 GMT
D/OkHttp: Server: Apache
D/OkHttp: Cache-Control: no-cache, private
D/OkHttp: X-RateLimit-Limit: 60
D/OkHttp: X-RateLimit-Remaining: 58
D/OkHttp: Vary: Authorization,User-Agent
D/OkHttp: Content-Length: 0
D/OkHttp: Keep-Alive: timeout=5, max=100
D/OkHttp: Connection: Keep-Alive
D/OkHttp: Content-Type: text/html; charset=UTF-8
D/OkHttp: <-- END HTTP (0-byte body)

如果需要进一步的翻译或解释,请随时提问。

英文:

This is the code for APIInterface:

@Multipart
    @POST(&quot;paytm&quot;)
    @Headers({&quot;Content-Type: application/json;charset=UTF-8&quot;})
    Call&lt;Token_Res&gt; generateTokenCall(
            @HeaderMap Map&lt;String, String&gt; header,
            @Part(&quot;code&quot;) RequestBody language,
            @Part (&quot;MID&quot;) RequestBody mid,
            @Part(&quot;ORDER_ID&quot;) RequestBody order_id,
            @Part(&quot;AMOUNT&quot;) RequestBody amount
    );

This is my Retrofit class:

package com.csk.jagdishshop.paytm;

import com.csk.jagdishshop.BuildConfig;
import com.csk.jagdishshop.NullOnEmptyConverterFactory;
import com.csk.jagdishshop.retrofit.APIService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ServiceWrapper {
    private APIService mServiceInterface;

    public ServiceWrapper(Interceptor mInterceptorheader) {
        mServiceInterface = getRetrofit(mInterceptorheader).create(APIService.class);
    }

    public Retrofit getRetrofit(Interceptor mInterceptorheader) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient mOkHttpClient = null;
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(1201, TimeUnit.SECONDS);
        builder.readTimeout(901, TimeUnit.SECONDS);

        if (BuildConfig.DEBUG) {
//            HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addInterceptor(loggingInterceptor);
        }

        mOkHttpClient = builder.build();
        Gson gson = new GsonBuilder().setLenient().create();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(&quot;https://jagdishshop.com/api/&quot;)
                .addConverterFactory(new NullOnEmptyConverterFactory())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(mOkHttpClient)
                .build();
        return retrofit;
    }

    public Call&lt;Token_Res&gt; getTokenCall(Map&lt;String, String&gt; header, String code, String mid, String order_id, String amount) {
        return mServiceInterface.generateTokenCall(
                header,convertPlainString(code), convertPlainString(mid), convertPlainString(order_id)
                , convertPlainString(amount)
                );
    }
    // convert aa param into plain text
    public RequestBody convertPlainString(String data){
        RequestBody plainString = RequestBody.create(data,MediaType.parse(&quot;text/plain&quot;));
        return  plainString;
    }
}

This is the network calling activity:
getToken() method is used to generate token from paytm server. For that i used the init_transaction.php file and PaytmCehcsum.php file on my own server and requesting to that. header is for the Authorization:token to validate the user.

private  void getToken(){
        Map&lt;String, String&gt; header = new HashMap&lt;&gt;();
        header.put(&quot;Authorization&quot;,token);
        header.put(&quot;X-Requested-With&quot;,&quot;XMLHttpRequest&quot;);

        Log.e(TAG, &quot; get token start&quot;);
        progressBar.setVisibility(View.VISIBLE);
        ServiceWrapper serviceWrapper = new ServiceWrapper(null);
        Call&lt;Token_Res&gt; call = serviceWrapper.getTokenCall(header,&quot;12345&quot;, midString, orderIdString, txnAmountString);
        call.enqueue(new Callback&lt;Token_Res&gt;() {
            @Override
            public void onResponse(Call&lt;Token_Res&gt; call, Response&lt;Token_Res&gt; response) {
                Log.e(TAG, &quot; respo &quot;+ response.isSuccessful());
                Log.e(TAG,&quot;response :&quot;+response.body());
                progressBar.setVisibility(View.GONE);
                try {

                    if (response.isSuccessful() &amp;&amp; response.body()!=null){
                        if (response.body().getBody().getTxnToken()!=&quot;&quot;) {
                            Log.e(TAG, &quot; transaction token : &quot;+response.body().getBody().getTxnToken());
                            startPaytmPayment(response.body().getBody().getTxnToken());
                        }else {
                            Log.e(TAG, &quot; Token status false&quot;);
                        }
                    }
                }catch (Exception e){
                    Log.e(TAG, &quot; error in Token Res &quot;+e.toString());
                }
            }

            @Override
            public void onFailure(Call&lt;Token_Res&gt; call, Throwable t) {
                progressBar.setVisibility(View.GONE);
                Log.e(TAG, &quot; response error &quot;+t.toString());
            }
        });

    }

    public void startPaytmPayment (String token){

        txnTokenString = token;
        
        String host = &quot;https://securegw.paytm.in/&quot;;
        String orderDetails = &quot;MID: &quot; + midString + &quot;, OrderId: &quot; + orderIdString + &quot;, TxnToken: &quot; + txnTokenString
                + &quot;, Amount: &quot; + txnAmountString;
        //Log.e(TAG, &quot;order details &quot;+ orderDetails);

        String callBackUrl = host + &quot;theia/paytmCallback?ORDER_ID=&quot;+orderIdString;
        Log.e(TAG, &quot; callback URL &quot;+callBackUrl);
        PaytmOrder paytmOrder = new PaytmOrder(orderIdString, midString, txnTokenString, txnAmountString, callBackUrl);
        TransactionManager transactionManager = new TransactionManager(paytmOrder, new PaytmPaymentTransactionCallback(){
            @Override
            public void onTransactionResponse(Bundle bundle) {
                Log.e(TAG, &quot;Response (onTransactionResponse) : &quot;+bundle.toString());
            }

            @Override
            public void networkNotAvailable() {
                Log.e(TAG, &quot;network not available &quot;);
            }

            @Override
            public void onErrorProceed(String s) {
                Log.e(TAG, &quot; onErrorProcess &quot;+s.toString());
            }

            @Override
            public void clientAuthenticationFailed(String s) {
                Log.e(TAG, &quot;Clientauth &quot;+s);
            }

            @Override
            public void someUIErrorOccurred(String s) {
                Log.e(TAG, &quot; UI error &quot;+s);
            }

            @Override
            public void onErrorLoadingWebPage(int i, String s, String s1) {
                Log.e(TAG, &quot; error loading web &quot;+s+&quot;--&quot;+s1);
            }

            @Override
            public void onBackPressedCancelTransaction() {
                Log.e(TAG, &quot;backPress &quot;);
            }

            @Override
            public void onTransactionCancel(String s, Bundle bundle) {
                Log.e(TAG, &quot; transaction cancel &quot;+s);
            }
        });

        transactionManager.setShowPaymentUrl(host + &quot;theia/api/v1/showPaymentPage&quot;);
        transactionManager.startTransaction(this, ActivityRequestCode);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.e(TAG ,&quot; result code &quot;+resultCode);
        
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == ActivityRequestCode &amp;&amp; data != null) {
            Bundle bundle = data.getExtras();
            if (bundle != null) {
                for (String key : bundle.keySet()) {
                    Log.e(TAG, key + &quot; : &quot; + (bundle.get(key) != null ? bundle.get(key) : &quot;NULL&quot;));
                }
            }
            Log.e(TAG, &quot; data &quot;+  data.getStringExtra(&quot;nativeSdkForMerchantMessage&quot;));
            Log.e(TAG, &quot; data response - &quot;+data.getStringExtra(&quot;response&quot;));

            Toast.makeText(getApplicationContext(), data.getStringExtra(&quot;nativeSdkForMerchantMessage&quot;)
                    + data.getStringExtra(&quot;response&quot;), Toast.LENGTH_SHORT).show();
        }else{
            Log.e(TAG, &quot; payment failed&quot;);
        }
    }

Here everytime I am getting response = true & responseBody = null

This is the Logcat output:

D/OkHttp: --&gt; POST https://jagdishshop.com/api/paytm http/1.1
D/OkHttp: Content-Type: application/json;charset=UTF-8
D/OkHttp: Content-Length: 816
D/OkHttp: Authorization: Bearer ...
D/OkHttp: X-Requested-With: XMLHttpRequest
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name=&quot;code&quot;
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 5
D/OkHttp: 12345
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name=&quot;MID&quot;
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 20
D/OkHttp: QKBnVxxxxxxxxx65
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name=&quot;ORDER_ID&quot;
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 4
D/OkHttp: 8361
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda
D/OkHttp: Content-Disposition: form-data; name=&quot;AMOUNT&quot;
D/OkHttp: Content-Transfer-Encoding: binary
D/OkHttp: Content-Type: text/plain; charset=utf-8
D/OkHttp: Content-Length: 3
D/OkHttp: 100
D/OkHttp: --a67ac3f9-93a3-4a87-bdf5-85b447044dda--
D/OkHttp: --&gt; END POST (816-byte body)

D/OkHttp: &lt;-- 200 OK https://jagdishshop.com/api/paytm (329ms)
D/OkHttp: Date: Tue, 15 Sep 2020 05:53:09 GMT
D/OkHttp: Server: Apache
D/OkHttp: Cache-Control: no-cache, private
D/OkHttp: X-RateLimit-Limit: 60
D/OkHttp: X-RateLimit-Remaining: 58
D/OkHttp: Vary: Authorization,User-Agent
D/OkHttp: Content-Length: 0
D/OkHttp: Keep-Alive: timeout=5, max=100
D/OkHttp: Connection: Keep-Alive
D/OkHttp: Content-Type: text/html; charset=UTF-8
D/OkHttp: &lt;-- END HTTP (0-byte body)

答案1

得分: 1

问题可能是您向https://jagdishshop.com/api/paytm发送了POST请求,而不是PayTM。\n除非您修复了服务器端的实现,否则试图修复客户端是极其没有意义的。

英文:

The problem might be, that you POST to https://jagdishshop.com/api/paytm instead of PayTM.
Unless you'd fix your server-side implementation, it is extremely pointless trying to fix the client.

答案2

得分: 0

请在启动交易 API 中使用以下回调 URL(服务器端实现)。

Staging: https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<ORDER_ID_HERE>
Production: https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<ORDER_ID_HERE>

英文:

Please use below callback URL in Initiate transaction API (Server-side implementation).

Staging: https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=&lt;ORDER_ID_HERE>
Production: https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=&lt;ORDER_ID_HERE>

huangapple
  • 本文由 发表于 2020年9月15日 13:35:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63895722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定