英文:
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("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
);
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("https://jagdishshop.com/api/")
.addConverterFactory(new NullOnEmptyConverterFactory())
.addConverterFactory(GsonConverterFactory.create(gson))
.client(mOkHttpClient)
.build();
return retrofit;
}
public Call<Token_Res> getTokenCall(Map<String, String> 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("text/plain"));
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<String, String> header = new HashMap<>();
header.put("Authorization",token);
header.put("X-Requested-With","XMLHttpRequest");
Log.e(TAG, " get token start");
progressBar.setVisibility(View.VISIBLE);
ServiceWrapper serviceWrapper = new ServiceWrapper(null);
Call<Token_Res> call = serviceWrapper.getTokenCall(header,"12345", midString, orderIdString, txnAmountString);
call.enqueue(new Callback<Token_Res>() {
@Override
public void onResponse(Call<Token_Res> call, Response<Token_Res> response) {
Log.e(TAG, " respo "+ response.isSuccessful());
Log.e(TAG,"response :"+response.body());
progressBar.setVisibility(View.GONE);
try {
if (response.isSuccessful() && response.body()!=null){
if (response.body().getBody().getTxnToken()!="") {
Log.e(TAG, " transaction token : "+response.body().getBody().getTxnToken());
startPaytmPayment(response.body().getBody().getTxnToken());
}else {
Log.e(TAG, " Token status false");
}
}
}catch (Exception e){
Log.e(TAG, " error in Token Res "+e.toString());
}
}
@Override
public void onFailure(Call<Token_Res> call, Throwable t) {
progressBar.setVisibility(View.GONE);
Log.e(TAG, " response error "+t.toString());
}
});
}
public void startPaytmPayment (String token){
txnTokenString = token;
String host = "https://securegw.paytm.in/";
String orderDetails = "MID: " + midString + ", OrderId: " + orderIdString + ", TxnToken: " + txnTokenString
+ ", Amount: " + txnAmountString;
//Log.e(TAG, "order details "+ orderDetails);
String callBackUrl = host + "theia/paytmCallback?ORDER_ID="+orderIdString;
Log.e(TAG, " callback URL "+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, "Response (onTransactionResponse) : "+bundle.toString());
}
@Override
public void networkNotAvailable() {
Log.e(TAG, "network not available ");
}
@Override
public void onErrorProceed(String s) {
Log.e(TAG, " onErrorProcess "+s.toString());
}
@Override
public void clientAuthenticationFailed(String s) {
Log.e(TAG, "Clientauth "+s);
}
@Override
public void someUIErrorOccurred(String s) {
Log.e(TAG, " UI error "+s);
}
@Override
public void onErrorLoadingWebPage(int i, String s, String s1) {
Log.e(TAG, " error loading web "+s+"--"+s1);
}
@Override
public void onBackPressedCancelTransaction() {
Log.e(TAG, "backPress ");
}
@Override
public void onTransactionCancel(String s, Bundle bundle) {
Log.e(TAG, " transaction cancel "+s);
}
});
transactionManager.setShowPaymentUrl(host + "theia/api/v1/showPaymentPage");
transactionManager.startTransaction(this, ActivityRequestCode);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(TAG ," result code "+resultCode);
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ActivityRequestCode && data != null) {
Bundle bundle = data.getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Log.e(TAG, key + " : " + (bundle.get(key) != null ? bundle.get(key) : "NULL"));
}
}
Log.e(TAG, " data "+ data.getStringExtra("nativeSdkForMerchantMessage"));
Log.e(TAG, " data response - "+data.getStringExtra("response"));
Toast.makeText(getApplicationContext(), data.getStringExtra("nativeSdkForMerchantMessage")
+ data.getStringExtra("response"), Toast.LENGTH_SHORT).show();
}else{
Log.e(TAG, " payment failed");
}
}
Here everytime I am getting response = true & responseBody = null
This is the Logcat output:
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)
答案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=<ORDER_ID_HERE>
Production: https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<ORDER_ID_HERE>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论