public ActionResult payson_confirmation(Int32 id = 0) { // Get the webshop settings KeyStringList webshopSettings = WebshopSetting.GetAllFromCache(); // Get the order Order order = Order.GetOneById(id); // Make sure that the order not is null if (order == null) { // Redirect the user to the order confirmation page return RedirectToAction("index", "home"); } // Get the payment token string token = order.payment_token; // Get credentials string userId = webshopSettings.Get("PAYSON-AGENT-ID"); string md5Key = webshopSettings.Get("PAYSON-MD5-KEY"); bool paysonTest = false; bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest); // Create the payson api PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest); // Create the response PaysonIntegration.Response.PaymentDetailsResponse response = null; try { // Make the payment details request response = paysonApi.MakePaymentDetailsRequest(new PaysonIntegration.Data.PaymentDetailsData(token)); } catch(Exception ex) { string exMessage = ex.Message; } // Check if the response is successful or not if (response != null && response.Success == true) { // Get the type and status of the payment PaysonIntegration.Utils.PaymentType? paymentType = response.PaymentDetails.PaymentType; PaysonIntegration.Utils.PaymentStatus? paymentStatus = response.PaymentDetails.PaymentStatus; PaysonIntegration.Utils.InvoiceStatus? invoiceStatus = response.PaymentDetails.InvoiceStatus; // Check if the paymentstatus is completed or ordercreated if (paymentType == PaysonIntegration.Utils.PaymentType.Direct && paymentStatus == PaysonIntegration.Utils.PaymentStatus.Completed) { // Update the order status Order.UpdatePaymentStatus(id, "payment_status_paid"); // Add customer files CustomerFile.AddCustomerFiles(order); } else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.OrderCreated) { // Update the order status Order.UpdatePaymentStatus(id, "payment_status_invoice_approved"); // Add customer files CustomerFile.AddCustomerFiles(order); } } // Redirect the user to the order confirmation page return RedirectToAction("confirmation", "order", new { id = id }); } // End of the payson_confirmation method
} // End of the paypal_confirmation method #endregion #region Payson payment /// <summary> /// Create a payson payment /// </summary> /// <param name="order">A reference to a order</param> /// <param name="orderRows">A reference to a list of order rows</param> /// <param name="domain">A reference to the domain</param> /// <param name="tt">A reference to translated texts</param> /// <param name="paymentType">The payment type, INVOICE, DIRECT</param> /// <returns>A redirect to payson</returns> public ActionResult CreatePaysonPayment(Order order, List<OrderRow> orderRows, Domain domain, KeyStringList tt, string paymentType) { // Get the webshop settings KeyStringList webshopSettings = WebshopSetting.GetAllFromCache(); // Get the language Language language = Language.GetOneById(domain.front_end_language); // Get credentials string paysonEmail = webshopSettings.Get("PAYSON-EMAIL"); string userId = webshopSettings.Get("PAYSON-AGENT-ID"); string md5Key = webshopSettings.Get("PAYSON-MD5-KEY"); bool paysonTest = false; bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest); // Set urls string returnUrl = domain.web_address + "/order/payson_confirmation/" + order.id.ToString(); string notificationUrl = domain.web_address + "/api/payments/payson_notification/" + order.id.ToString(); string cancelUrl = domain.web_address + "/order/confirmation/" + order.id.ToString(); // Create the sender PaysonIntegration.Utils.Sender sender = new PaysonIntegration.Utils.Sender(order.customer_email); sender.FirstName = "@"; sender.LastName = "@"; // Get the total amount decimal totalAmount = order.total_sum - order.gift_cards_amount; // Create the receiver List<PaysonIntegration.Utils.Receiver> receivers = new List<PaysonIntegration.Utils.Receiver>(1); PaysonIntegration.Utils.Receiver receiver = new PaysonIntegration.Utils.Receiver(paysonEmail, totalAmount); receiver.SetPrimaryReceiver(true); receivers.Add(receiver); // Create a list of order items List<PaysonIntegration.Utils.OrderItem> orderItems = new List<PaysonIntegration.Utils.OrderItem>(10); // Add order items for (int i = 0; i < orderRows.Count; i++) { // Create a order item PaysonIntegration.Utils.OrderItem orderItem = new PaysonIntegration.Utils.OrderItem(orderRows[i].product_name); orderItem.SetOptionalParameters(orderRows[i].product_code, orderRows[i].quantity, orderRows[i].unit_price, orderRows[i].vat_percent); // Add the order item to the list orderItems.Add(orderItem); } // Add the rounding if(order.rounding_sum != 0) { PaysonIntegration.Utils.OrderItem roundingItem = new PaysonIntegration.Utils.OrderItem(tt.Get("rounding")); roundingItem.SetOptionalParameters("rd", 1, order.rounding_sum, 0); orderItems.Add(roundingItem); } // Add the gift cards amount if (order.gift_cards_amount > 0) { PaysonIntegration.Utils.OrderItem giftCardItem = new PaysonIntegration.Utils.OrderItem(tt.Get("gift_cards")); giftCardItem.SetOptionalParameters("gc", 1, order.gift_cards_amount * -1, 0); orderItems.Add(giftCardItem); } // Create funding constraints depending on the payment method List<PaysonIntegration.Utils.FundingConstraint> fundingConstraints = new List<PaysonIntegration.Utils.FundingConstraint>(); if (paymentType == "INVOICE") { fundingConstraints.Add(PaysonIntegration.Utils.FundingConstraint.Invoice); } else if(paymentType == "DIRECT") { fundingConstraints.Add(PaysonIntegration.Utils.FundingConstraint.Bank); fundingConstraints.Add(PaysonIntegration.Utils.FundingConstraint.CreditCard); } // Create the order memo string orderMemo = tt.Get("order").ToUpper() + "# " + order.id.ToString(); // Create the pay data PaysonIntegration.Data.PayData payData = new PaysonIntegration.Data.PayData(returnUrl, cancelUrl, orderMemo, sender, receivers); payData.SetFundingConstraints(fundingConstraints); payData.GuaranteeOffered = PaysonIntegration.Utils.GuaranteeOffered.No; payData.SetLocaleCode(AnnytabDataValidation.GetPaysonLocaleCode(language)); payData.SetCurrencyCode(order.currency_code); payData.SetOrderItems(orderItems); payData.ShowReceiptPage = false; payData.SetIpnNotificationUrl(notificationUrl); payData.SetTrackingId(order.id.ToString()); // Create the api PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest); // Create a respone PaysonIntegration.Response.PayResponse response = null; try { // Create the payment response = paysonApi.MakePayRequest(payData); } catch(Exception ex) { string exMessage = ex.Message; } // Check if the response is successful string forwardUrl = ""; if (response != null && response.Success == true) { // Update the order with the payment token Order.SetPaymentToken(order.id, response.Token); // Get the forward url forwardUrl = paysonApi.GetForwardPayUrl(response.Token); // Redirect the user to the forward url return Redirect(forwardUrl); } else { // Redirect the user to the order confirmation page return RedirectToAction("confirmation", "order", new { id = order.id }); } } // End of the CreatePaysonPayment
public async Task<HttpResponseMessage> payson_notification(Int32 id = 0) { // Read the content string content = await Request.Content.ReadAsStringAsync(); // Check for errors if (content == null || content == "") { return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The content is null or empty"); } // Get the webshop settings KeyStringList webshopSettings = WebshopSetting.GetAllFromCache(); // Get the order Order order = Order.GetOneById(id); // Make sure that the orde exists if (order == null) { return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The order does not exist"); } // Get credentials string userId = webshopSettings.Get("PAYSON-AGENT-ID"); string md5Key = webshopSettings.Get("PAYSON-MD5-KEY"); bool paysonTest = false; bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest); // Create the payson api PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest); // Validate the content PaysonIntegration.Response.ValidateResponse validateResponse = paysonApi.MakeValidateIpnContentRequest(content); // Check if the validation was successful if (validateResponse.Success) { // Get the data PaysonIntegration.Utils.PaymentType? paymentType = validateResponse.ProcessedIpnMessage.PaymentType; PaysonIntegration.Utils.PaymentStatus? paymentStatus = validateResponse.ProcessedIpnMessage.PaymentStatus; PaysonIntegration.Utils.InvoiceStatus? invoiceStatus = validateResponse.ProcessedIpnMessage.InvoiceStatus; // Check the payment type and payment status if (paymentType == PaysonIntegration.Utils.PaymentType.Direct && paymentStatus == PaysonIntegration.Utils.PaymentStatus.Completed) { // Update the order status Order.UpdatePaymentStatus(id, "payment_status_paid"); // Add customer files CustomerFile.AddCustomerFiles(order); } else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.OrderCreated) { // Update the order status Order.UpdatePaymentStatus(id, "payment_status_invoice_approved"); // Add customer files CustomerFile.AddCustomerFiles(order); } } // Return the success response return Request.CreateResponse<string>(HttpStatusCode.OK, "The post has been processed"); } // End of the payson_notification method
public async Task <HttpResponseMessage> payson_notification(Int32 id = 0) { // Read the content string content = await Request.Content.ReadAsStringAsync(); // Check for errors if (content == null || content == "") { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The content is null or empty")); } // Get the webshop settings KeyStringList webshopSettings = WebshopSetting.GetAllFromCache(); // Get the order Order order = Order.GetOneById(id); // Make sure that the orde exists if (order == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The order does not exist")); } // Get credentials string userId = webshopSettings.Get("PAYSON-AGENT-ID"); string md5Key = webshopSettings.Get("PAYSON-MD5-KEY"); bool paysonTest = false; bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest); // Create the payson api PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest); // Validate the content PaysonIntegration.Response.ValidateResponse validateResponse = paysonApi.MakeValidateIpnContentRequest(content); // Check if the validation was successful if (validateResponse.Success) { // Get the data PaysonIntegration.Utils.PaymentType? paymentType = validateResponse.ProcessedIpnMessage.PaymentType; PaysonIntegration.Utils.PaymentStatus?paymentStatus = validateResponse.ProcessedIpnMessage.PaymentStatus; PaysonIntegration.Utils.InvoiceStatus?invoiceStatus = validateResponse.ProcessedIpnMessage.InvoiceStatus; // Check the payment type and payment status if (paymentType == PaysonIntegration.Utils.PaymentType.Direct && paymentStatus == PaysonIntegration.Utils.PaymentStatus.Completed) { // Update the order status Order.UpdatePaymentStatus(id, "payment_status_paid"); // Add customer files CustomerFile.AddCustomerFiles(order); } else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.OrderCreated) { // Update the order status Order.UpdatePaymentStatus(id, "payment_status_invoice_approved"); // Add customer files CustomerFile.AddCustomerFiles(order); } } // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been processed")); } // End of the payson_notification method
} // End of the UpdatePaymentStatus method /// <summary> /// Respond to an updated order status /// </summary> /// <param name="order"></param> /// <param name="paymentOption"></param> /// <param name="orderStatus"></param> /// <returns></returns> private string UpdateOrderStatus(Order order, PaymentOption paymentOption, string orderStatus) { // Create the string to return string error_message = ""; // Get the current domain Domain domain = Tools.GetCurrentDomain(); // Get webshop settings KeyStringList webshopSettings = WebshopSetting.GetAllFromCache(); // Check the order status if (orderStatus == "order_status_delivered") { if(paymentOption.connection == 102) // Payson invoice { // Get credentials string paysonEmail = webshopSettings.Get("PAYSON-EMAIL"); string userId = webshopSettings.Get("PAYSON-AGENT-ID"); string md5Key = webshopSettings.Get("PAYSON-MD5-KEY"); bool paysonTest = false; bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest); // Create the api PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest); // Update the order PaysonIntegration.Data.PaymentUpdateData paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.ShipOrder); PaysonIntegration.Response.PaymentUpdateResponse paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData); // Check if the response is successful if (paymentUpdateResponse != null && paymentUpdateResponse.Success == false) { // Set error messages foreach (string key in paymentUpdateResponse.ErrorMessages) { error_message += "• " + "Payson: " + paymentUpdateResponse.ErrorMessages[key] + "<br/>"; } } } else if(paymentOption.connection == 301) // Svea invoice { // Get the order rows List<OrderRow> orderRows = OrderRow.GetByOrderId(order.id); // Create the payment configuration SveaSettings sveaConfiguration = new SveaSettings(); // Create the order builder Webpay.Integration.CSharp.Order.Handle.DeliverOrderBuilder inoviceBuilder = Webpay.Integration.CSharp.WebpayConnection.DeliverOrder(sveaConfiguration); // Add order rows for (int i = 0; i < orderRows.Count; i++) { // Get the unit Unit unit = Unit.GetOneById(orderRows[i].unit_id, domain.back_end_language); // Create an order item Webpay.Integration.CSharp.Order.Row.OrderRowBuilder orderItem = new Webpay.Integration.CSharp.Order.Row.OrderRowBuilder(); orderItem.SetArticleNumber(orderRows[i].product_code); orderItem.SetName(orderRows[i].product_name); orderItem.SetQuantity(orderRows[i].quantity); orderItem.SetUnit(unit.unit_code); orderItem.SetAmountExVat(orderRows[i].unit_price); orderItem.SetVatPercent(orderRows[i].vat_percent * 100); // Add the order item inoviceBuilder.AddOrderRow(orderItem); } // Get the order id Int64 sveaOrderId = 0; Int64.TryParse(order.payment_token, out sveaOrderId); // Set invoice values inoviceBuilder.SetOrderId(sveaOrderId); inoviceBuilder.SetNumberOfCreditDays(15); inoviceBuilder.SetInvoiceDistributionType(Webpay.Integration.CSharp.Util.Constant.InvoiceDistributionType.POST); inoviceBuilder.SetCountryCode(SveaSettings.GetSveaCountryCode(order.country_code)); // Make the request to send the invoice Webpay.Integration.CSharp.WebpayWS.DeliverOrderEuResponse deliverOrderResponse = inoviceBuilder.DeliverInvoiceOrder().DoRequest(); // Check if the response is successful if (deliverOrderResponse.Accepted == false) { // Set error messages error_message += "• " + "Svea code: " + deliverOrderResponse.ResultCode.ToString() + "<br/>"; error_message += "• " + "Svea message: " + deliverOrderResponse.ErrorMessage + "<br/>"; } } else if (paymentOption.connection >= 400 && paymentOption.connection <= 499) // Payex { // Check the transaction Dictionary<string, string> payexResponse = PayExManager.CheckTransaction(order, webshopSettings); // Get response variables string error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : ""; string description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : ""; string parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : ""; string transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : ""; string transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : ""; // Check if the response was successful if (error_code.ToUpper() == "OK") { if(transaction_status == "3") // Authorize { // Capture the transaction payexResponse = PayExManager.CaptureTransaction(order); // Get response variables error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : ""; description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : ""; parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : ""; transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : ""; transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : ""; string transaction_number_original = payexResponse.ContainsKey("transaction_number_original") == true ? payexResponse["transaction_number_original"] : ""; if(error_code.ToUpper() != "OK" || transaction_status != "6") { // Set error messages error_message += "• " + "Payex code: " + error_code + "<br/>"; error_message += "• " + "Payex message: " + description + "<br/>"; error_message += "• " + "Payex parameter: " + parameter_name + "<br/>"; error_message += "• " + "Payex status: " + transaction_status + "<br/>"; error_message += "• " + "Payex number (original): " + transaction_number + "<br/>"; } else { // Update the transaction number for the order Order.SetPaymentToken(order.id, transaction_number); } } } else { // Set error messages error_message += "• " + "Payex code: " + error_code + "<br/>"; error_message += "• " + "Payex message: " + description + "<br/>"; error_message += "• " + "Payex parameter: " + parameter_name + "<br/>"; error_message += "• " + "Payex status: " + transaction_status + "<br/>"; error_message += "• " + "Payex number: " + transaction_number + "<br/>"; } } } else if (orderStatus == "order_status_cancelled") { if(paymentOption.connection >= 100 && paymentOption.connection <= 199) // Payson { // Get credentials string paysonEmail = webshopSettings.Get("PAYSON-EMAIL"); string userId = webshopSettings.Get("PAYSON-AGENT-ID"); string md5Key = webshopSettings.Get("PAYSON-MD5-KEY"); bool paysonTest = false; bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest); // Create the api PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest); // Get details about the payment status PaysonIntegration.Response.PaymentDetailsResponse paysonResponse = paysonApi.MakePaymentDetailsRequest(new PaysonIntegration.Data.PaymentDetailsData(order.payment_token)); // Get the type and status of the payment PaysonIntegration.Utils.PaymentType? paymentType = paysonResponse.PaymentDetails.PaymentType; PaysonIntegration.Utils.PaymentStatus? paymentStatus = paysonResponse.PaymentDetails.PaymentStatus; PaysonIntegration.Utils.InvoiceStatus? invoiceStatus = paysonResponse.PaymentDetails.InvoiceStatus; // Payment update PaysonIntegration.Data.PaymentUpdateData paymentUpdateData = null; PaysonIntegration.Response.PaymentUpdateResponse paymentUpdateResponse = null; if (paymentType == PaysonIntegration.Utils.PaymentType.Direct && paymentStatus == PaysonIntegration.Utils.PaymentStatus.Completed) { // Refund the payment paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.Refund); paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData); } else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.OrderCreated) { // Cancel the order paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.CancelOrder); paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData); } else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && (invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.Shipped || invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.Done)) { // Credit the order paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.CreditOrder); paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData); } // Check if there was any errors if (paymentUpdateResponse != null && paymentUpdateResponse.Success == false) { // Set error messages foreach (string key in paymentUpdateResponse.ErrorMessages) { error_message += "• " + "Payson: " + paymentUpdateResponse.ErrorMessages[key] + "<br/>"; } } } else if(paymentOption.connection == 201) // PayPal { // Get credentials string paypalClientId = webshopSettings.Get("PAYPAL-CLIENT-ID"); string paypalClientSecret = webshopSettings.Get("PAYPAL-CLIENT-SECRET"); string paypalMode = webshopSettings.Get("PAYPAL-MODE"); Dictionary<string, string> config = new Dictionary<string, string> { { "mode", paypalMode } }; try { // Create the credential token PayPal.OAuthTokenCredential tokenCredential = new PayPal.OAuthTokenCredential(paypalClientId, paypalClientSecret, config); // Create the api context PayPal.APIContext paypalContext = new PayPal.APIContext(tokenCredential.GetAccessToken()); paypalContext.Config = config; // Look up the sale PayPal.Api.Payments.Sale sale = PayPal.Api.Payments.Sale.Get(paypalContext, order.payment_token); if (sale.state == "completed") { // Refund the payment paypalContext.HTTPHeaders = null; PayPal.Api.Payments.Refund refund = sale.Refund(paypalContext, new PayPal.Api.Payments.Refund()); if(refund.state != "completed") { error_message += "• " + "PayPal: " + refund.state; } } else { error_message += "• " + "PayPal: " + sale.state; } } catch (Exception ex) { error_message += "• PayPal: " + ex.Message; } } else if(paymentOption.connection == 301) // Svea invoice { // Create the payment configuration SveaSettings sveaConfiguration = new SveaSettings(); // Get the order id Int64 sveaOrderId = 0; Int64.TryParse(order.payment_token, out sveaOrderId); // Cancel the order Webpay.Integration.CSharp.Order.Handle.CloseOrderBuilder closeOrder = Webpay.Integration.CSharp.WebpayConnection.CloseOrder(sveaConfiguration); closeOrder.SetOrderId(sveaOrderId); closeOrder.SetCountryCode(SveaSettings.GetSveaCountryCode(order.country_code)); Webpay.Integration.CSharp.WebpayWS.CloseOrderEuResponse closeOrderResponse = closeOrder.CloseInvoiceOrder().DoRequest(); // Check if the response is successful if (closeOrderResponse.Accepted == false) { // Set error messages error_message += "• " + "Svea code: " + closeOrderResponse.ResultCode.ToString() + "<br/>"; error_message += "• " + "Svea message: " + closeOrderResponse.ErrorMessage + "<br/>"; } } else if(paymentOption.connection >= 400 && paymentOption.connection <= 499) // Payex { // Check the transaction Dictionary<string, string> payexResponse = PayExManager.CheckTransaction(order, webshopSettings); // Get response variables string error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : ""; string description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : ""; string parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : ""; string transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : ""; string transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : ""; // Check if the response was successful if(error_code.ToUpper() == "OK") { // Check if we should cancel or credit the order if(transaction_status == "3") // Authorize { // Cancel the transaction payexResponse = PayExManager.CancelTransaction(order, webshopSettings); // Get response variables error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : ""; description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : ""; parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : ""; transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : ""; transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : ""; if(error_code.ToUpper() != "OK" || transaction_status != "4") { // Set error messages error_message += "• " + "Payex code: " + error_code + "<br/>"; error_message += "• " + "Payex message: " + description + "<br/>"; error_message += "• " + "Payex parameter: " + parameter_name + "<br/>"; error_message += "• " + "Payex status: " + transaction_status + "<br/>"; error_message += "• " + "Payex number: " + transaction_number + "<br/>"; } } else if(transaction_status == "0" || transaction_status == "6") // Sale or capture { // Get the order rows List<OrderRow> orderRows = OrderRow.GetByOrderId(order.id); // Credit the transaction payexResponse = PayExManager.CreditTransaction(order, orderRows, webshopSettings); // Get response variables error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : ""; description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : ""; parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : ""; transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : ""; transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : ""; if (error_code.ToUpper() != "OK" || transaction_status != "2") { // Set error messages error_message += "• " + "Payex code: " + error_code + "<br/>"; error_message += "• " + "Payex message: " + description + "<br/>"; error_message += "• " + "Payex parameter: " + parameter_name + "<br/>"; error_message += "• " + "Payex status: " + transaction_status + "<br/>"; error_message += "• " + "Payex number: " + transaction_number + "<br/>"; } } } else { // Set error messages error_message += "• " + "Payex code: " + error_code + "<br/>"; error_message += "• " + "Payex message: " + description + "<br/>"; error_message += "• " + "Payex parameter: " + parameter_name + "<br/>"; error_message += "• " + "Payex status: " + transaction_status + "<br/>"; error_message += "• " + "Payex number: " + transaction_number + "<br/>"; } } } // Return the error message return error_message; } // End of the UpdateOrderStatus method