processing payment but not saving transaction/order info

I am having an issue with an order payment process. I am sending the payment through iMIS and it is being charged in our PayPal account, but the payment is not being recorded in iMIS. The batch is generated, but keeps a $0 total and no product sale info is created. I have been researching it for many hours and cannot pinpoint the cause of my problem. If you have any ideas please share. Thank you. - JK

//create order
CStandardOrder stdOrder = new CStandardOrder(user);
//gets current days open batch or creates new one
CBatch batch = getBatch(user);
CStandardOrderLine line = stdOrder.NewLineItem("CORRECT_PRODUCT_CODE", 1);

//set stdOrder attributes
stdOrder.BatchNumber = batch.BatchNumber;
stdOrder.BillToContactId = contact.ContactId;
stdOrder.CashAccountCode = "XXXX";

//get order payment
CPayment payment = stdOrder.Payment;
//set payment info
payment.Amount = Settings.SESSION_TRAINING_PRICE;
payment.PaymentType = EnumPaymentType.CreditCard;
payment.CreditDebitCardHoldersName = TBcardName.Text.Trim();
payment.CreditCardNumber = TBcardNumber.Text.Trim();
payment.CreditCardSecurityCode = TBcardSecurity.Text.Trim();
payment.CreditCardExpiration = DDLexpMonth.SelectedValue + DDLexpYear.SelectedValue;
payment.CashAccountCode = "XXXX";

//get cashAccount code
Asi.iBO.SystemConfig.CCashAccount cashAccount = Asi.iBO.iboAdmin.ReferenceData.GetCashAccount(stdOrder.Payment.CashAccountCode);

//set billing address
CAddressBasic billAddr = new CAddressBasic(user);
billAddr.Address1 = txtAddress.Text.Trim();
billAddr.Address2 = txtAddress2.Text.Trim();
billAddr.City = txtCity.Text.Trim();
billAddr.StateProvince = txtState.Text.Trim();
billAddr.PostalCode = txtZipCode.Text.Trim();
billAddr.Validate();

//use payment gateway
PaymentGatewayResponse response = stdOrder.Payment.ProcessPayment(billAddr);

//save the order
stdOrder.Validate();
stdOrder.Save();

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Add this

 

payment.Validate();
stdOrder.Validate();
bool successFlag = stdOrder.Save();

if (successFlag)
     {                               
  CAccountingEvent newTrans = new CAccountingEvent(user);
  DataServer server = new DataServer(user);
  newTrans.StandardOrderEvent(server, Asi.iBO.Financials.AccountingEventType.ProFormaFullPurchase, stdOrder, Batch, payment);
  Asi.Bae.Business.Cart.CartOrder.ClearCachedCartOrders(_imisID);
      foreach (Asi.Bae.Business.Cart.CartOrder _item in Asi.Bae.Business.Cart.CartOrder.GetAll(_imisID, Cart))
      {
   _item.Dispose();
   _item.Cart.Delete();    
      }
      Session.Abandon();                             

     }

 

 

Bruce M Walker

BSCI

Chicago IL

There are 2 issues which I

There are 2 issues which I found from your code.

1. Always first assign billing contact then add product

2. Assign payment amount from order total

. Below code may help to resolve your problem about order total zero issue

 private double CreateOrder(string contactId, string productCode)
{
      double orderNumber;
      try
      {
            IiMISUser user = sql.getUser();
            CContact contact = new CContact(user, contactId);
            CStandardOrder order = new CStandardOrder(user) {
                  BillToContact = contact,
                  ShipToContact = contact
            };
            order.NewLineItem(productCode, 1.0);
            order.BatchNumber = sql.getBatch(user).BatchNumber;
            order.Payment.Amount = order.TotalCharges;
            order.Payment.PaymentType = EnumPaymentType.CreditCard;
            order.Payment.CreditCardNumber = "4444333322221111";
            order.Payment.CreditDebitCardHoldersName = "Name";
            order.Payment.CreditDebitCardAuthorizationCode = "123";
            order.Payment.CreditCardSecurityCode = "123";
            order.Payment.CreditCardExpiration = "12/50";
            order.Payment.CashAccountCode= "VISA";
            order.Payment.Validate();
            order.Validate();

            if (order.Errors.Count > 0)
            {
                  throw new Exception(order.Errors.PrimaryErrorMessage);
            }

            //CALL PAYMENT   
            order.Save();
            orderNumber = order.OrderNumber;
      }
      catch (Exception exception)
      {
            throw new Exception(exception.Message);
      }
      return orderNumber;
}

 

Question about the Standard Order event.

Will the order make it to the trans without?

newTrans.StandardOrderEvent(server, Asi.iBO.Financials.AccountingEventType.ProFormaFullPurchase, stdOrder, Batch, payment);
 

Bruce M Walker

BSCI

Chicago IL

Yes, Once you post your

Yes, Once you post your batch trans records will be created

  When do we use bool

 

When do we use

bool isDuesPaid = newTrans.DuesPaymentEvent(server, _CContact.Subscriptions, batch2, cpay);

or

newTrans.StandardOrderEvent(server, Asi.iBO.Financials.AccountingEventType.ProFormaFullPurchase, stdOrder, Batch, payment);

 
Bruce M Walker

BSCI

Chicago IL

Bruce M Walker

BSCI

Chicago IL