/*
*
*/
package com.ewallet.citygo.utils;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.util.Log;
import com.ewallet.citygo.bean.TransactionCreateBean;
import com.ewallet.citygo.bean.TransactionStatusBean;
import com.ewallet.citygo.config.AppConfig;
import com.ewallet.citygo.manager.AccountManager;
// TODO: Auto-generated Javadoc
/**
* The Class Transaction.
*/
public class Transaction {
/**
* Creates the.
*
* @param bean the bean
* @param source_id the source_id
* @param source_count the source_count
* @param tpaytype the tpaytype
* @param price the price
* @return true, if successful
*/
public boolean create(TransactionCreateBean bean, int source_id, int source_count, String tpaytype, int price) {
boolean result = false;
SoapObject request = new SoapObject(AppConfig.NAMESPACE, "create");
request.addProperty("source_id", source_id);
request.addProperty("source_count", source_count);
request.addProperty("tpaytype", tpaytype);
request.addProperty("price", price);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(AppConfig.SERVER_SITE + AppConfig.JAVA_TRANSACTION_SITE);
try {
androidHttpTransport.call(AppConfig.SERVER_SITE + AppConfig.JAVA_TRANSACTION_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
bean.status = getInt(response, "status");
bean.message = getString(response, "message");
bean.txId = getInt(response, "txId");
AccountManager.getAccountManager().myAccount.setTransactionId(String.valueOf(bean.txId));
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* Listen status.
*
* @param bean the bean
* @param tx_id the tx_id
* @return true, if successful
*/
public boolean listenStatus(TransactionStatusBean bean, int tx_id) {
boolean result = false;
SoapObject request = new SoapObject(AppConfig.NAMESPACE, "listenStatus");
request.addProperty("tx_id", tx_id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(AppConfig.SERVER_SITE + AppConfig.JAVA_TRANSACTION_SITE);
try {
androidHttpTransport.call(AppConfig.SERVER_SITE + AppConfig.JAVA_TRANSACTION_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
bean.status = getInt(response, "tstatus");
Log.v("ListenStatus", String.valueOf(bean.status));
if (bean.status == 1)
result = true;
} catch (Exception e) {
}
return result;
}
/**
* Scan update info.
*
* @param source_id the source_id
* @param source_count the source_count
* @param price the price
* @param dest_id the dest_id
* @param dest_count the dest_count
* @param tx_id the tx_id
* @param issuer the issuer
* @param serial_no the serial_no
* @param card_id the card_id
* @param card_no the card_no
* @return true, if successful
*/
public boolean scanUpdateInfo(int source_id, int source_count, int price,
int dest_id, int dest_count, int tx_id,
String issuer, String serial_no, int card_id, String card_no) {
TransactionStatusBean bean = new TransactionStatusBean();
boolean result = false;
SoapObject request = new SoapObject(AppConfig.NAMESPACE, "scanUpdateInfo");
request.addProperty("source_id", source_id);
request.addProperty("source_count", source_count);
request.addProperty("tpaytype", "1");
request.addProperty("price", price);
request.addProperty("dest_id", dest_id);
request.addProperty("dest_count", dest_count);
request.addProperty("tx_id", tx_id);
request.addProperty("issuer", issuer);
request.addProperty("serial_no", serial_no);
request.addProperty("card_id", card_id);
request.addProperty("card_no", card_no);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(AppConfig.SERVER_SITE + AppConfig.JAVA_TRANSACTION_SITE);
try {
androidHttpTransport.call(AppConfig.SERVER_SITE + AppConfig.JAVA_TRANSACTION_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
bean.status = getInt(response, "status");
bean.message = getString(response, "message");
if (getInt(response, "tstatus") == 1)
result = true;
} catch (Exception e) {
}
return result;
}
/**
* Gets the int.
*
* @param response the response
* @param name the name
* @return the int
*/
private int getInt(SoapObject response, String name) {
return Integer.parseInt(response.getProperty(name).toString());
}
/**
* Gets the string.
*
* @param response the response
* @param name the name
* @return the string
*/
private String getString(SoapObject response, String name) {
return response.getProperty(name).toString();
}
}
沒有留言:
張貼留言