I have two radio group button (Cash on Delivery and PayOnline) when I click cash on delivery it passes all the related data of cart and customer detalis, but when i click to PayOnline it passes to another activity where it ask to fill the amount...?? I am using ATOM PAYMENT GATEWAY LIBRARY
here is my code
ActivityPayment.java
package com.www.prashant;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.atom.mobilepaymentsdk.PayActivity;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
/**
* Created by Dev on 10/1/2015.
*/
public class ActivityPaymentOption extends Fragment{
private RadioGroup radioPaymentGroup;
private RadioButton radioCOD,radioON;
private Button placeOrder;
private TextView textView;
View view;
ProgressDialog pdialog;
ProgressDialog pDialog;
String getCustomerDataResult;
String getCustomerDataResult2;
String getCustomerDataResult3;
String getCustomerDataResult4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((MainActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((MainActivity)getActivity()).actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
Constants.lastDetails = true;
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.payment_option, container, false);
//Set Navigation mode as Statndard
((MainActivity)getActivity()).getSupportActionBar().setNavigationMode(((MainActivity) getActivity()).getSupportActionBar().NAVIGATION_MODE_STANDARD);
view = v;
radioPaymentGroup = (RadioGroup) v.findViewById(R.id.radioPaymentMethod);
placeOrder = (Button) v.findViewById(R.id.buttonPlaceOrder);
radioCOD = (RadioButton) v.findViewById(R.id.radioCOD);
radioON = (RadioButton) v.findViewById(R.id.radioON);
//textView = (TextView) v.findViewById(R.id.textShipping);
placeOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// get selected radio button from radioGroup
int selectedId = radioPaymentGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
if(selectedId == radioCOD.getId()) {
radioCOD = (RadioButton) view.findViewById(selectedId);
Toast.makeText(getActivity(), radioCOD.getText(), Toast.LENGTH_SHORT).show();
new getDataTask().execute();
} else if(selectedId == radioON.getId()) {
radioON = (RadioButton) view.findViewById(selectedId);
Toast.makeText(getActivity(), radioON.getText(), Toast.LENGTH_SHORT).show();
Intent newPayIntent = new Intent(getActivity(), MPSActivity.class);
startActivity(newPayIntent);
}
}
});
return v;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
((MainActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((MainActivity)getActivity()).actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
// ProductsListFragment productsListFragment=new ProductsListFragment();
// getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_content, productsListFragment, null).addToBackStack(null).commit();
// getActivity().setTitle(Constants.Category_name.get(Constants.position - 1));
MainActivity.getInstance().CallFragment(Constants.position);
}
return true;
}
public class getDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
if (pdialog==null){
pdialog=new ProgressDialog(getActivity());
pdialog.setMessage("Loading...");
pdialog.setCanceledOnTouchOutside(getRetainInstance());
pdialog.setCancelable(false);
pdialog.show();
}
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
// parse json data from server in background
shoppingCartShippingMethod();
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
if (pdialog.isShowing()){
pdialog.dismiss();
pdialog=null;
}
//textView.setText(getCustomerDataResult3);
//Toast.makeText(getActivity(),"Result1:=> "+ getCustomerDataResult2, Toast.LENGTH_SHORT).show();
//Toast.makeText(getActivity(),"Result: "+ getCustomerDataResult4, Toast.LENGTH_SHORT).show();
if (getCustomerDataResult4!=null){
Toast.makeText(getActivity(), "Order Placed", Toast.LENGTH_LONG).show();
}
else
Constants.OrderNo = Integer.parseInt(getCustomerDataResult4);
OrderConfirmation orderConfirmation=new OrderConfirmation();
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_content,orderConfirmation,null).addToBackStack(null).commit();
getActivity().setTitle("Order");
}
}
// method to set shopping Cart Shipping Method
public void shoppingCartShippingMethod(){
try {
// add paramaters and values
SoapObject request = new SoapObject(Constants.NAMESPACE, "shoppingCartShippingMethod");
request.addProperty("sessionId", Constants.sessionId);
request.addProperty("quoteId", Constants.cartId);
request.addProperty("method", "flatrate_flatrate");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
//Web method call
HttpTransportSE androidHttpTransport = new HttpTransportSE(Constants.URL);
androidHttpTransport.debug = true;
androidHttpTransport.call("", envelope);
//get the response
String result = String.valueOf(envelope.getResponse());
getCustomerDataResult2 = result.toString();
// // Call shopping Cart Payment Method
if(getCustomerDataResult2.equals("true")){
shoppingCartPaymentMethod();
}
else {
getCustomerDataResult = "false";
return;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (XmlPullParserException e) {
e.printStackTrace();
}
}
// method to set shopping Cart Payment Method
public void shoppingCartPaymentMethod(){
try {
SoapObject PaymentMethodEntity = new SoapObject(Constants.NAMESPACE, "shoppingCartPaymentMethodEntity");
PaymentMethodEntity.addProperty("method","cashondelivery");
// add paramaters and values
SoapObject request = new SoapObject(Constants.NAMESPACE, "shoppingCartPaymentMethod");
request.addProperty("sessionId", Constants.sessionId);
request.addProperty("quoteId", Constants.cartId);
request.addProperty("method", PaymentMethodEntity);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
//Web method call
HttpTransportSE androidHttpTransport = new HttpTransportSE(Constants.URL);
androidHttpTransport.debug = true;
androidHttpTransport.call("", envelope);
//get the response
String result = String.valueOf(envelope.getResponse());
getCustomerDataResult3 = result.toString();
// // Call Place shopping Cart Order
if(getCustomerDataResult3.equals("true")){
shoppingCartOrder();
}
else {
getCustomerDataResult = "false";
return;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (XmlPullParserException e) {
e.printStackTrace();
}
}
// method to Place shopping Cart Order
public void shoppingCartOrder(){
try {
// add paramaters and values
SoapObject request = new SoapObject(Constants.NAMESPACE, "shoppingCartOrder");
request.addProperty("sessionId", Constants.sessionId);
request.addProperty("quoteId", Constants.cartId);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
//Web method call
HttpTransportSE androidHttpTransport = new HttpTransportSE(Constants.URL);
androidHttpTransport.debug = true;
androidHttpTransport.call("", envelope);
//get the response
String result = String.valueOf(envelope.getResponse());
getCustomerDataResult4 = result.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (XmlPullParserException e) {
e.printStackTrace();
}
}
}
MPSACTIVITY.JAVA
package com.www.prashant;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.atom.mobilepaymentsdk.PayActivity;
public class MPSActivity extends Activity implements OnClickListener {
Button payMerchantNB;
TextView et_nb_amt;
ProgressDialog pdialog;
View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
System.out.println("In On Resume");
setContentView(R.layout.mainpage);
et_nb_amt = (EditText) findViewById(R.id.et_nb_amt);
payMerchantNB = (Button) findViewById(R.id.btn_payMerchantNB);
payMerchantNB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String amt = et_nb_amt.getText().toString();
if (amt.equalsIgnoreCase("")) {
Toast.makeText(MPSActivity.this, "Please enter valid amount", Toast.LENGTH_LONG).show();
}
else {
Double doubleAmt = Double.valueOf(amt);
amt = doubleAmt.toString();
Intent newPayIntent = new Intent(MPSActivity.this, PayActivity.class);
newPayIntent.putExtra("merchantId", "1111");
newPayIntent.putExtra("txnscamt", "0"); //Fixed. Must be �0�
newPayIntent.putExtra("loginid", "1111");
newPayIntent.putExtra("password", "TEST@123");
newPayIntent.putExtra("prodid", "TEST");
newPayIntent.putExtra("txncurr", "INR"); //Fixed. Must be �INR�
newPayIntent.putExtra("clientcode", "007");
newPayIntent.putExtra("custacc", "100000036600");
newPayIntent.putExtra("amt", amt);//Should be 3 decimal number i.e 1.000
newPayIntent.putExtra("txnid", "013");
newPayIntent.putExtra("date", "25/08/2015 18:31:00");//Should be in same format
newPayIntent.putExtra("bankid", ""); //Should be valid bank id
//use below Production url only with Production "Library-MobilePaymentSDK", Located inside PROD folder
newPayIntent.putExtra("ru", "https://payment.atomtech.in/mobilesdk/param"); //ru FOR Production
//use below UAT url only with UAT "Library-MobilePaymentSDK", Located inside UAT folder
//newPayIntent.putExtra("ru", "https://paynetzuat.atomtech.in/mobilesdk/param"); // FOR UAT (Testing)
//Optinal Parameters
newPayIntent.putExtra("customerName", "PRASHANT"); //Only for Name
newPayIntent.putExtra("customerEmailId", "prashantlaldas@gmail.com");//Only for Email ID
newPayIntent.putExtra("customerMobileNo", "xx85048450");//Only for Mobile Number
newPayIntent.putExtra("billingAddress", "Mumbai");//Only for Address
newPayIntent.putExtra("optionalUdf9", "OPTIONAL DATA 1");// Can pass any data
startActivityForResult(newPayIntent, 1);
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
System.out.println("RESULTCODE--->" + resultCode);
System.out.println("REQUESTCODE--->" + requestCode);
System.out.println("RESULT_OK--->" + RESULT_OK);
if (requestCode == 1) {
System.out.println("---------INSIDE-------");
if (data != null) {
String message = data.getStringExtra("status");
String[] resKey = data.getStringArrayExtra("responseKeyArray");
String[] resValue = data.getStringArrayExtra("responseValueArray");
if (resKey != null && resValue != null) {
for (int i = 0; i < resKey.length; i++)
System.out.println(" " + i + " resKey : " + resKey[i] + " resValue : " + resValue[i]);
}
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
System.out.println("RECEIVED BACK--->" + message);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}