I see that the team is working on a few more payment gateways. I have built a payment gateway adapting the WorldPay code. We use a Commonwealth Bank - Commweb - Dialect system for secure credit card payments.

It seams this new payment gateway works a little bit different to the existing payment gateways in nop in that the website talks to an application running on our server which in turn formats the data which we post to their URL. The customer then uses the Commonwealth Bank website and enters their card details, etc. Once the transaction is completed and Approved their website does a callback to a page on our website to update the order and complete the transaction.

But the thing is the returned packet they send in the callback has the Result of the transaction, Payement Transaction ID and Reciept number, etc and so you can tell if it has been so why not store the values in the order here.

So I have adapted the worldpay payment module and the return code and some code from MarkAsPaid to create the handler below which is used to finish it off. It works fine but after looking at again I was thinking maybe i should have been calling Capture in the Payment Module ?

Has anyone done anything with writing these values to the order? Simple enough - it just seemed like a big overhead to call the Payment Module Capture code to do it - assume it would have worked once i'd worked it out.

If the return routine was all part of the Payment Module then I suppose I would have. Anyway maybe in the next release I will look at it again and see how things work then. Any thoughts / problems you can see ?

// Code for Payment Gateway Return

               if (qsiResponseCode == "0") // returned packet has been decoded correctly
                    {
                
                    // Check if Success

                    try
                    {                    
                    
                        string callbackPassword = SettingManager.GetSettingValue("PaymentMethod.Commweb.CallbackPassword");
                        if (string.IsNullOrEmpty(callbackPassword))
                            throw new NopException("Commweb callback password is not set");

                        instanceID = SettingManager.GetSettingValue("PaymentMethod.Commweb.InstanceID");
                        if (string.IsNullOrEmpty(instanceID))
                                throw new NopException("Commweb Instance ID is not set");

                        if (instanceID.Trim() != merchTxnRef.Trim())
                            throw new NopException(string.Format("The Instance ID (0}) received for order {1} does not match the Commweb Instance ID stored in the database ({2})", merchTxnRef, orderInfo, instanceID));
    
                        // Get and Update order details and Set Order Status to be Completed

                        Order order = OrderManager.GetOrderByID(Convert.ToInt32(orderInfo));
                        if (order == null)
                            throw new NopException(string.Format("The order ID {0} doesn't exists", orderInfo));

                        if (order.CustomerID != NopContext.Current.User.CustomerID)
                            throw new NopException("Not your order");


                        // Maybe could of called Capture in the payment module but instead just
                        // write the values here as part of an addapted "mark as paid" routine

                        var processPaymentResult = new ProcessPaymentResult();
                        processPaymentResult.AVSResult = cardType;
                        processPaymentResult.AuthorizationTransactionID = authorizeID;
                        processPaymentResult.AuthorizationTransactionCode = acqResponseCode;
                        processPaymentResult.AuthorizationTransactionResult = cscResultCode;
                        processPaymentResult.CaptureTransactionID = transactionNr;
                        processPaymentResult.CaptureTransactionResult = receiptNo;
                        processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
                                
                        OrderManager.UpdateOrder(order.OrderID, order.OrderGUID, order.CustomerID, order.CustomerLanguageID,
                            order.CustomerTaxDisplayType, order.CustomerIP, order.OrderSubtotalInclTax, order.OrderSubtotalExclTax, order.OrderShippingInclTax,
                            order.OrderShippingExclTax, order.PaymentMethodAdditionalFeeInclTax, order.PaymentMethodAdditionalFeeExclTax,
                            order.OrderTax, order.OrderTotal, order.OrderDiscount,
                            order.OrderSubtotalInclTaxInCustomerCurrency, order.OrderSubtotalExclTaxInCustomerCurrency,
                            order.OrderShippingInclTaxInCustomerCurrency, order.OrderShippingExclTaxInCustomerCurrency,
                            order.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency, order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency,
                            order.OrderTaxInCustomerCurrency, order.OrderTotalInCustomerCurrency,
                            order.OrderDiscountInCustomerCurrency, order.CustomerCurrencyCode, order.OrderWeight,
                            order.AffiliateID, OrderStatusEnum.Complete, order.AllowStoringCreditCardNumber,
                            processPaymentResult.AVSResult, order.CardName, order.CardNumber, order.MaskedCreditCardNumber,
                            order.CardCVV2, order.CardExpirationMonth, order.CardExpirationYear,
                            order.PaymentMethodID, order.PaymentMethodName,
                            processPaymentResult.AuthorizationTransactionID,
                            processPaymentResult.AuthorizationTransactionCode,
                            processPaymentResult.AuthorizationTransactionResult,
                            processPaymentResult.CaptureTransactionID,
                            processPaymentResult.CaptureTransactionResult,
                            processPaymentResult.SubscriptionTransactionID,
                            order.PurchaseOrderNumber, processPaymentResult.PaymentStatus, DateTime.Now,
                            order.BillingFirstName, order.BillingLastName, order.BillingPhoneNumber,
                            order.BillingEmail, order.BillingFaxNumber, order.BillingCompany, order.BillingAddress1,
                            order.BillingAddress2, order.BillingCity,
                            order.BillingStateProvince, order.BillingStateProvinceID, order.BillingZipPostalCode,
                            order.BillingCountry, order.BillingCountryID, order.ShippingStatus,
                            order.ShippingFirstName, order.ShippingLastName, order.ShippingPhoneNumber,
                            order.ShippingEmail, order.ShippingFaxNumber, order.ShippingCompany,
                            order.ShippingAddress1, order.ShippingAddress2, order.ShippingCity,
                            order.ShippingStateProvince, order.ShippingStateProvinceID, order.ShippingZipPostalCode,
                            order.ShippingCountry, order.ShippingCountryID,
                            order.ShippingMethod, order.ShippingRateComputationMethodID, order.ShippedDate,
                            order.TrackingNumber, order.Deleted, order.CreatedOn);

                        OrderManager.InsertOrderNote(order.OrderID, string.Format("Order has been Paid"), false, DateTime.Now);
                        
                        Response.Redirect("~/CheckoutCompleted.aspx");
                        }
                    
                    catch (Exception ex)
                        {
                        message = "(100) Error writing Order Paid Details";
                        exception = ex.Message;
                        }
                    }


                // Not ended successfully so send the customer to the account page by default

Response.Redirect("~/Account.aspx");
}