Implementing a payment transaction

About this task

To implement a payment transaction, do the following:

Procedure

  1. Define the payment transaction in paymentOp.xml.
    <paymentOp.xml>
      <operation context="paymentCtx" id="paymentOp" implClass="com.ibm.btt.sample.operation.PaymentOperation">
        <refFormat name="csReplyFormat" refId="paymentSecondRecFmt" />
      </operation>
    </paymentOp.xml>
  2. Define the payment context in dsectxt.xml.
    <context id="paymentCtx" type="oper">
      <refKColl refId="paymentData"/>
    </context>
  3. Define the payment data element in dsedata.xml.
    <bColl id="paymentData" bean="com.ibm.btt.sample.data.PaymentBean" />
  4. Define the payment java bean.
    public class PaymentBean {
    	 String acctFrom;
    	 String acctTo;
    	 String pageName;
    	 String TrxReplyCode;
    	 String amount;
    	 double acctToBalance;
    	 double acctFromBalance;
    	
    	
    	public String getAmount() {
    		return amount;
    	}
    	public void setAmount(String amount) {
    		this.amount = amount;
    	}
    	public double getAcctToBalance() {
    		return acctToBalance;
    	}
    	public void setAcctToBalance(double acctToBalance) {
    		this.acctToBalance = acctToBalance;
    	}
    	public double getAcctFromBalance() {
    		return acctFromBalance;
    	}
    	public void setAcctFromBalance(double acctFromBalance) {
    		this.acctFromBalance = acctFromBalance;
    	}
    	public String getAcctFrom() {
    		return acctFrom;
    	}
    	public void setAcctFrom(String acctFrom) {
    		this.acctFrom = acctFrom;
    	}
    	public String getAcctTo() {
    		return acctTo;
    	}
    	public void setAcctTo(String acctTo) {
    		this.acctTo = acctTo;
    	}
    	public String getPageName() {
    		return pageName;
    	}
    	public void setPageName(String pageName) {
    		this.pageName = pageName;
    	}
    	public String getTrxReplyCode() {
    		return TrxReplyCode;
    	}
    	public void setTrxReplyCode(String trxReplyCode) {
    		TrxReplyCode = trxReplyCode;
    	}
  5. Define the payment data format in dsefmts.xml.
    • Format definition used for payment transaction in Web 2.0 channel:
      <fmtDef id="paymentXMLFmt">
      <fXML dataName="paymentData">
      <fString dataName="acctFrom" />
      <fString dataName="acctTo" />
      <fString dataName="amount" />
      </fXML>
      </fmtDef>
      
      <fmtDef id="transferFirstRecFmt">
      <record>
      
      </record>
      </fmtDef>
    • Format definition used for payment transaction in HTML channel, JSF channel, Rich Client:
      <fmtDef id="paymentSecondRecFmt">
      		<record>
      			<fString dataName="TrxReplyCode" />
      			<delim delimChar="#" />
      		</record>
      	</fmtDef>
      <fmtDef id="paymentSecondReqFmt">
      		<record>
      			<constant value="Tx06" />
      			<delim delimChar="#" />
      			<fString dataName="acctFrom" />
      			<delim delimChar="#" />
      			<fString dataName="acctTo" />
      			<delim delimChar="#" />
      			<fString dataName="amount" />
      			<delim delimChar="#" />
      		</record>
      	</fmtDef>
  6. Define the Web Service invoker for payment transaction in invoker.xml.
    <WSDII id="paymentWS" wsdlURL="http://localhost:9080/BackendEmulatorWeb/wsdl/Payment.wsdl"
        operation="PaymentOperation">
      <parameters>
        <wsDIIparameter id="cardReq"  />
      </parameters>
    </WSDII>
  7. Implement the execute() method of payment transaction in <toolkit_root>/samples/BTTMultiChannleSample/SampleBusiness/com.ibm.btt.sample.operation.PaymentOperation.java:
    		String useWebService="false";
    		WSDynamicInvoker  wsinvoker=null;
    		useWebService=mark.getString("useWebService");
    		try{
    			if(useWebService.equals("true")){
    			System.out.println("useWebService==="+useWebService);
    			wsinvoker=(WSDynamicInvoker) InvokerFactory.getDefaultInvokerFactory().createInvoker("paymentWS");
    			
    			//Call a web service
    			
    			WebServiceInfo wsinfo= wsinvoker.getWsInfo();
    			System.out.println("PaymentOperation request context ="+this.getContext().getKeyedCollection());
    			UserDefineTypeInfo paymentReqType = wsinfo.getUserDefineTypeByName("PaymentReqType");
    			UserDefineTypeInfo paymentResponseType = wsinfo.getUserDefineTypeByName("PaymentResponseType");
    			GenericDataObject cardReq = wsinvoker.convertContexDataToGenericDataObject(wsinvoker.getParameters().get("cardReq") , paymentReqType, this.getContext());
    			Object result =  wsinvoker.execute(new Object[]{ cardReq  });
    			System.out.println("PaymentOperation  call web service, result="+result);
    			if ( result instanceof GenericDataObject)
    				wsinvoker.convertGenericDataObjectToContext( wsinvoker.getParameters().get("cardReq") , paymentResponseType, (GenericDataObject) result, this.getContext());
    			
    			// Set the page to display for HTML channel
    			}
    			
    			setValueAt(HtmlConstants.REPLYPAGE, "paymentcomplete.jsp");
    			setValueAt("errorCode", HtmlException.OK);
    			setValueAt("TrxReplyCode","OK");
    			setValueAt("outcome","succcess");
    			System.out.println("set data completed");
    		}catch(Exception e){
    			e.printStackTrace();
    		}
    Note: The block of code demonstrates how to use BTT Web Service invoker to call a Web Service application.