コード例 #1
0
ファイル: PSTakePayment.cs プロジェクト: altras/fmi_projects
        public void Process(OrderProcessor processor)
        {
            // set processor reference
              orderProcessor = processor;
              // audit
              orderProcessor.CreateAudit("PSTakePayment started.", 20400);
              try
              {
            // take customer funds via DataCash gateway
            // configure DataCash XML request
            DataCashRequest request = new DataCashRequest();
            request.Authentication.Client =
              BalloonShopConfiguration.DataCashClient;

            request.Authentication.Password =
              BalloonShopConfiguration.DataCashPassword;
            request.Transaction.HistoricTxn.Method =
              "fulfill";
            request.Transaction.HistoricTxn.AuthCode =
              orderProcessor.Order.AuthCode;
            request.Transaction.HistoricTxn.Reference =
              orderProcessor.Order.Reference;
            // get DataCash response
            DataCashResponse response =
              request.GetResponse(
              BalloonShopConfiguration.DataCashUrl);
            if (true || response.Status == "1")
            {
              // audit
              orderProcessor.CreateAudit(
            "Funds deducted from customer credit card account.",
            20402);
              // update order status
              orderProcessor.Order.UpdateStatus(5);
              // continue processing
              orderProcessor.ContinueNow = true;
            }
            else
            {
              // audit
              orderProcessor.CreateAudit(
               "Error taking funds from customer credit card account.",
               20403);
              // mail admin
              orderProcessor.MailAdmin(
            "Credit card fulfillment declined.",
            "XML data exchanged:\n" + request.Xml + "\n\n" +
            response.Xml, 1);
            }
              }
              catch
              {
            // fund checking failure
            throw new OrderProcessorException(
              "Error occured while taking payment.", 4);
              }
              // audit
              processor.CreateAudit("PSTakePayment finished.", 20401);
        }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Prepare StringBuilder for output
        StringBuilder sb = new StringBuilder();

        // Initialize variables
        DataCashRequest request;
        XmlSerializer requestSerializer =
           new XmlSerializer(typeof(DataCashRequest));
        DataCashResponse response;
        XmlSerializer responseSerializer =
           new XmlSerializer(typeof(DataCashResponse));
        StringBuilder xmlBuilder;
        StringWriter xmlWriter;
        string dataCashUrl =
           "https://testserver.datacash.com/Transaction";
        string dataCashClient = "99341800";
        string dataCashPassword = "******";

        // Construct pre request
        request = new DataCashRequest();
        request.Authentication.Client = dataCashClient;
        request.Authentication.Password = dataCashPassword;
        request.Transaction.TxnDetails.MerchantReference = "9999999";
        request.Transaction.TxnDetails.Amount.Amount = "49.99";
        request.Transaction.TxnDetails.Amount.Currency = "GBP";
        request.Transaction.CardTxn.Method = "pre";
        request.Transaction.CardTxn.Card.CardNumber =
           "4444333322221111";
        request.Transaction.CardTxn.Card.ExpiryDate = "10/11";

        // Display pre request
        sb.AppendLine("Pre Request:");
        xmlBuilder = new StringBuilder();
        xmlWriter = new StringWriter(xmlBuilder);
        requestSerializer.Serialize(xmlWriter, request);
        sb.AppendLine(xmlBuilder.ToString());
        sb.AppendLine();

        // Get pre response
        response = request.GetResponse(dataCashUrl);

        // Display pre response
        sb.AppendLine("Pre Response:");
        xmlBuilder = new StringBuilder();
        xmlWriter = new StringWriter(xmlBuilder);
        responseSerializer.Serialize(xmlWriter, response);
        sb.AppendLine(xmlBuilder.ToString());
        sb.AppendLine();

        // Construct fulfil request
        request = new DataCashRequest();
        request.Authentication.Client = dataCashClient;
        request.Authentication.Password = dataCashPassword;
        request.Transaction.HistoricTxn.Method = "fulfill";
        request.Transaction.HistoricTxn.AuthCode =
           response.MerchantReference;
        request.Transaction.HistoricTxn.Reference =
           response.DatacashReference;

        // Display fulfil request
        sb.AppendLine("Fulfil Request:");
        xmlBuilder = new StringBuilder();
        xmlWriter = new StringWriter(xmlBuilder);
        requestSerializer.Serialize(xmlWriter, request);
        sb.AppendLine(xmlBuilder.ToString());
        sb.AppendLine();

        // Get fulfil response
        response = request.GetResponse(dataCashUrl);

        // Display fulfil response
        sb.AppendLine("Fulfil Response:");
        xmlBuilder = new StringBuilder();
        xmlWriter = new StringWriter(xmlBuilder);
        responseSerializer.Serialize(xmlWriter, response);
        sb.AppendLine(xmlBuilder.ToString());

        // Output result
        OutputBox.Text = sb.ToString();
    }
コード例 #3
0
 public void Process(OrderProcessor processor)
 {
     // set processor reference
       orderProcessor = processor;
       // audit
       orderProcessor.CreateAudit("PSCheckFunds started.", 20100);
       try
       {
     // check customer funds via DataCash gateway
     // configure DataCash XML request
     DataCashRequest request = new DataCashRequest();
     request.Authentication.Client =
        BalloonShopConfiguration.DataCashClient;
     request.Authentication.Password =
        BalloonShopConfiguration.DataCashPassword;
     request.Transaction.TxnDetails.MerchantReference =
       orderProcessor.Order.OrderID.ToString()
       .PadLeft(6, '0').PadLeft(7, '5');
     request.Transaction.TxnDetails.Amount.Amount =
       orderProcessor.Order.TotalCost.ToString();
     request.Transaction.TxnDetails.Amount.Currency = "GBP";
     request.Transaction.CardTxn.Method = "pre";
     request.Transaction.CardTxn.Card.CardNumber =
       orderProcessor.Order.CreditCard.CardNumber;
     request.Transaction.CardTxn.Card.ExpiryDate =
       orderProcessor.Order.CreditCard.ExpiryDate;
     if (orderProcessor.Order.CreditCard.IssueDate != "")
     {
       request.Transaction.CardTxn.Card.StartDate =
     orderProcessor.Order.CreditCard.IssueDate;
     }
     if (orderProcessor.Order.CreditCard.IssueNumber != "")
     {
       request.Transaction.CardTxn.Card.IssueNumber =
     orderProcessor.Order.CreditCard.IssueNumber;
     }
     // get DataCash response
     DataCashResponse response =
       request.GetResponse(
       BalloonShopConfiguration.DataCashUrl);
     if (response.Status == "1")
     {
       // update order authorization code and reference
       orderProcessor.Order.SetAuthCodeAndReference(
     response.MerchantReference,
     response.DatacashReference);
       // audit
       orderProcessor.CreateAudit(
     "Funds available for purchase.", 20102);
       // update order status
       orderProcessor.Order.UpdateStatus(2);
       // continue processing
       orderProcessor.ContinueNow = true;
     }
     else
     {
       // audit
       orderProcessor.CreateAudit(
     "Funds not available for purchase.", 20103);
       // mail admin
       orderProcessor.MailAdmin("Credit card declined.",
     "XML data exchanged:\n" + request.Xml + "\n\n"
     + response.Xml, 1);
     }
       }
       catch
       {
     // fund checking failure
     throw new OrderProcessorException(
       "Error occured while checking funds.", 1);
       }
       // audit
       processor.CreateAudit("PSCheckFunds finished.", 20101);
 }