我正在尝试根据此链接“ https://developer.paytm.com/docs/v1/android-sdk/”实现Paytm网关,但是在应用程序Webview中打开,我陷入了Paytms处理页面。以下是我正在尝试的演示代码。请帮忙,因为Paytm没有帮助。我没有丢失任何参数,因为如果删除/更改任何参数,它将显示特定参数的错误。 首先,我要在服务器上创建订单ID,然后是校验和,然后调用Paytm服务。 使用相同校验和的同一件事在PC浏览器上有效,但在android上无效。
public class MainActivity extends AppCompatActivity {
APIinterface apiInterface;
String order_id,paytmschecksum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_SMS, Manifest.permission.RECEIVE_SMS}, 101);
}
get_orderid();
}
public void get_orderid(){
apiInterface = APIClient.getClient().create(APIinterface.class);
Call<List<OrderID_response>> call = apiInterface.get_orderid("1","rxazcv89315285244163");
call.enqueue(new Callback<List<OrderID_response>>() {
@Override
public void onResponse(Call<List<OrderID_response>> call, Response<List<OrderID_response>> response) {
// Toast.makeText(LocationUpdateService.this, response.toString(), Toast.LENGTH_SHORT).show();
List<OrderID_response> details = response.body();
if(details!=null){
if(details.get(0).getResponse().equalsIgnoreCase("success")){
order_id = details.get(0).getUnique_id();
Log.d("Order Id :", order_id );
get_paytmchecksum();
}
}
}
@Override
public void onFailure(Call<List<OrderID_response>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failure:" +t, Toast.LENGTH_SHORT).show();
Log.d(TAG, "onFailure: "+t.toString());
}
});
}
// Checksum for paytm
public void get_paytmchecksum(){
apiInterface = APIClient.getClient().create(APIinterface.class);
Call<List<paytm_checksum_model>> call = apiInterface.get_paytmchecksum_temp("email@gmail.comm","7777777777","1",order_id,"100.00"); //100 is recharge amount change it after testing
call.enqueue(new Callback<List<paytm_checksum_model>>() {
@Override
public void onResponse(Call<List<paytm_checksum_model>> call, Response<List<paytm_checksum_model>> response) {
// Toast.makeText(LocationUpdateService.this, response.toString(), Toast.LENGTH_SHORT).show();
List<paytm_checksum_model> details = response.body();
if(details!=null){
paytmschecksum = details.get(0).getCheckSum();
Log.d("Checksum : ", paytmschecksum );
paytm();
}
}
@Override
public void onFailure(Call<List<paytm_checksum_model>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failure:" +t, Toast.LENGTH_SHORT).show();
Log.d(TAG, "onFailure: "+t.toString());
}
});
}
public void paytm(){
PaytmPGService Service = PaytmPGService.getStagingService("https://securegw-stage.paytm.in/order/process");
HashMap paramMap = new HashMap<>();
paramMap.put( "MID" , "rxazcv89315285244163"); //My mid will be here.
// Key in your staging and production MID available in your dashboard
paramMap.put( "ORDER_ID" , order_id);
paramMap.put( "CUST_ID" , "1");
// paramMap.put( "MOBILE_NO" , "7777777777");
// paramMap.put( "EMAIL" , "email@gmail.com");
paramMap.put( "CHANNEL_ID" , "WEB");
paramMap.put( "TXN_AMOUNT" , "100.00");
paramMap.put( "WEBSITE" , "WEBSTAGING");
// This is the staging value. Production value is available in your dashboard
paramMap.put( "INDUSTRY_TYPE_ID" , "Retail");
// This is the staging value. Production value is available in your dashboard
paramMap.put( "CALLBACK_URL", "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp");
paramMap.put( "CHECKSUMHASH" , paytmschecksum);
PaytmOrder Order = new PaytmOrder(paramMap);
Service.initialize(Order, null);
Service.startPaymentTransaction(MainActivity.this, true, true, new PaytmPaymentTransactionCallback() {
public void someUIErrorOccurred(String inErrorMessage) {}
public void networkNotAvailable() {
Toast.makeText(MainActivity.this, "Network connection error: Check your internet connectivity", Toast.LENGTH_LONG).show();
}
public void clientAuthenticationFailed(String inErrorMessage) {
Toast.makeText(MainActivity.this, "Authentication failed: Server error" + inErrorMessage.toString(), Toast.LENGTH_LONG).show();
}
public void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingUrl) {
Toast.makeText(MainActivity.this, "Unable to load webpage " + inErrorMessage.toString(), Toast.LENGTH_LONG).show();
}
public void onBackPressedCancelTransaction() {}
public void onTransactionCancel(String inErrorMessage, Bundle inResponse) {}
public void onTransactionResponse(Bundle inResponse) {
Toast.makeText(MainActivity.this, "Payment Transaction response " + inResponse.toString(), Toast.LENGTH_LONG).show();
}
});
}
}
答案 0 :(得分:1)
发生这种情况是因为您的服务器可能您忘记返回响应 Paytm SDK 没有问题它在交易发生期间触发回调...
使用回调 URL Post Request "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=" 从服务器请求这个 url 创建自己的回调 URL 在您的服务器内
尝试从您的服务器端检查它会修复
答案 1 :(得分:0)
您应该集成其开发人员页面上提供的提供了多合一SDK的新SDK。请参考集成。
答案 2 :(得分:0)
Add Paytm All in One SDK dependency in Project-level Gradle file: -
allprojects {
repositories {
google()
jcenter()
maven {
url "https://artifactory.paytm.in/libs-release-local"
}
}
}
Now add another dependency in the module level Gradle file.
implementation ‘com.paytm.appinvokesdk:appinvokesdk:1.2’
MainActivity :
public class MainActivity extends AppCompatActivity {
private String TAG ="MainActivity";
private ProgressBar progressBar;
private EditText txnAmount;
private String midString ="Your Production mode MID here", txnAmountString="", orderIdString="", txnTokenString="";
private Button btnPayNow;
private Integer ActivityRequestCode = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnPayNow = (Button) findViewById(R.id.txnProcessBtn);
txnAmount = (EditText) findViewById(R.id.txnAmountId);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("ddMMyyyy");
String date = df.format(c.getTime());
Random rand = new Random();
int min =1000, max= 9999;
// nextInt as provided by Random is exclusive of the top value so you need to add 1
int randomNum = rand.nextInt((max - min) + 1) + min;
orderIdString = date+String.valueOf(randomNum);
btnPayNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txnAmountString = txnAmount.getText().toString();
String errors = "";
if(orderIdString.equalsIgnoreCase("")){
errors ="Enter valid Order ID here\n";
Toast.makeText(MainActivity.this, errors, Toast.LENGTH_SHORT).show();
}else
if(txnAmountString.equalsIgnoreCase("")){
errors ="Enter valid Amount here\n";
Toast.makeText(MainActivity.this, errors, Toast.LENGTH_SHORT).show();
}else{
getToken();
}
}
});
}
private void getToken(){
Log.e(TAG, " get token start");
progressBar.setVisibility(View.VISIBLE);
ServiceWrapper serviceWrapper = new ServiceWrapper(null);
Call<Token_Res> call = serviceWrapper.getTokenCall("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() );
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;
// for test mode use it
// String host = "https://securegw-stage.paytm.in/";
// for production mode use it
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
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(TAG ," result code "+resultCode);
// -1 means successful // 0 means failed
// one error is - nativeSdkForMerchantMessage : networkError
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"));
/*
data response - {"BANKNAME":"WALLET","BANKTXNID":"1394221115",
"CHECKSUMHASH":"7jRCFIk6eRmrep+IhnmQrlrL43KSCSXrmM+VHP5pH0ekXaaxjt3MEgd1N9mLtWyu4VwpWexHOILCTAhybOo5EVDmAEV33rg2VAS/p0PXdk\u003d",
"CURRENCY":"INR","GATEWAYNAME":"WALLET","MID":"EAcP3138556","ORDERID":"100620202152",
"PAYMENTMODE":"PPI","RESPCODE":"01","RESPMSG":"Txn Success","STATUS":"TXN_SUCCESS",
"TXNAMOUNT":"2.00","TXNDATE":"2020-06-10 16:57:45.0","TXNID":"2020061011121280011018328631290118"}
*/
Toast.makeText(this, data.getStringExtra("nativeSdkForMerchantMessage")
+ data.getStringExtra("response"), Toast.LENGTH_SHORT).show();
}else{
Log.e(TAG, " payment failed");
}
}
}