public bool Capture(PaymentMethod currentPayment, string additionalValues) { Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment) currentPayment.Payment; Log.InfoFormat("Capturing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); int transactionId; if (!int.TryParse(payment.AuthorizationCode, out transactionId)) { Log.ErrorFormat("Could not get PayEx transaction ID from payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); return false; } Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId); long amount = payment.Amount.RoundToLong(); string orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber); CaptureResult result = _paymentManager.Capture(transactionId, amount, orderNumber, currentPayment.Payment.Vat, additionalValues); bool success = false; if (result.Success && !string.IsNullOrWhiteSpace(result.TransactionNumber)) { Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during capture", result.TransactionNumber, payment.Id, payment.OrderGroupId); payment.ValidationCode = result.TransactionNumber; PaymentStatusManager.ProcessPayment(payment); payment.AcceptChanges(); success = true; Log.InfoFormat("Successfully captured payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } if (_paymentCapturer != null) return _paymentCapturer.Capture(currentPayment) && success; return success; }
public bool ProcessSuccessfulTransaction(PayExPayment payExPayment, string orderNumber, string orderRef, Cart cart, out string transactionErrorCode) { transactionErrorCode = null; Log.InfoFormat("Processing a transaction for payment with ID:{0} belonging to order with ID: {1}. Order number: {2}. Order reference: {3}", payExPayment.Id, payExPayment.OrderGroupId, orderNumber, orderRef); PaymentMethod currentPayment = _paymentMethodFactory.Create(payExPayment); if (currentPayment == null) { Log.ErrorFormat("As the PaymentMethod for payment with ID:{0} could not be resolved, it cannot be processed by the PayEx Payment Provider!", payExPayment.Id); return(false); } Log.InfoFormat("Completing payment with ID:{0} belonging to order with ID: {1}", payExPayment.Id, payExPayment.OrderGroupId); PaymentCompleteResult result = currentPayment.Complete(orderRef); transactionErrorCode = result.TransactionErrorCode; if (!result.Success) { Log.ErrorFormat("Could not complete payment with ID:{0} belonging to order with ID: {1}. TransactionErrorCode: {2}", payExPayment.Id, payExPayment.OrderGroupId, transactionErrorCode); } else { Log.InfoFormat("Successfully completed payment with ID:{0} belonging to order with ID: {1}", payExPayment.Id, payExPayment.OrderGroupId); } return(result.Success); }
public bool Credit(PaymentMethod currentPayment) { Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment; Log.InfoFormat("Crediting payment with ID:{0} belonging to order with ID: {1}, by order lines", payment.Id, payment.OrderGroupId); int transactionId; if (!int.TryParse(payment.AuthorizationCode, out transactionId)) { Log.ErrorFormat("Could not get PayEx Transaction Id from purchase order with ID: {0}", currentPayment.PurchaseOrder.Id); return(false); } Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId); CreditResult result = null; string orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber); foreach (OrderForm orderForm in currentPayment.PurchaseOrder.OrderForms) { foreach (LineItem lineItem in orderForm.LineItems) { result = _paymentManager.CreditOrderLine(transactionId, lineItem.CatalogEntryId, orderNumber); } } bool success = false; if (result != null && !string.IsNullOrWhiteSpace(result.TransactionNumber)) { Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during credit", result.TransactionNumber, payment.Id, payment.OrderGroupId); payment.TransactionID = result.TransactionNumber; payment.AcceptChanges(); success = true; Log.InfoFormat("Successfully credited payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } if (_paymentCreditor != null) { return(_paymentCreditor.Credit(currentPayment) && success); } return(success); }
public PaymentCompleteResult Complete(PaymentMethod currentPayment, string orderRef) { Log.InfoFormat("Updating transaction details for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); string transactionString = ((Mediachase.Commerce.Orders.Payment)currentPayment.Payment).AuthorizationCode; Log.InfoFormat("Transaction number is:{0} for payment with ID:{1} belonging to order with ID: {2}", transactionString, currentPayment.Payment.Id, currentPayment.OrderGroupId); int transactionNumber; if (!Int32.TryParse(transactionString, out transactionNumber)) { Log.ErrorFormat("Could not parse Transaction number:{0} to an Int for payment with ID:{1} belonging to order with ID: {2}", transactionString, currentPayment.Payment.Id, currentPayment.OrderGroupId); return(new PaymentCompleteResult()); } TransactionResult transactionDetails = _paymentManager.GetTransactionDetails(transactionNumber); bool updated = false; if (transactionDetails != null) { updated = UpdateOrderAddress(currentPayment, transactionDetails); } PaymentCompleteResult result = new PaymentCompleteResult { Success = true }; if (_paymentCompleter != null) { result = _paymentCompleter.Complete(currentPayment, orderRef); } if (updated) { Log.InfoFormat("Successfully updated transaction details for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } result.Success = updated; return(result); }
public bool Credit(PaymentMethod currentPayment) { var payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment; Log.Info($"Crediting payment with ID:{payment.Id} belonging to order with ID: {payment.OrderGroupId}, by order lines"); int transactionId; if (!int.TryParse(payment.AuthorizationCode, out transactionId)) { Log.Error($"Could not get PayEx Transaction Id from purchase order with ID: {currentPayment.PurchaseOrder.Id}"); return false; } Log.Info($"PayEx transaction ID is {transactionId} on payment with ID:{payment.Id} belonging to order with ID: {payment.OrderGroupId}"); CreditResult result = null; var orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber); foreach (OrderForm orderForm in currentPayment.PurchaseOrder.OrderForms) { foreach (LineItem lineItem in orderForm.LineItems) { result = _paymentManager.CreditOrderLine(transactionId, lineItem.CatalogEntryId, orderNumber); } } var success = false; if (!string.IsNullOrWhiteSpace(result?.TransactionNumber)) { Log.Info($"Setting PayEx transaction number to {result.TransactionNumber} on payment with ID:{payment.Id} belonging to order with ID: {payment.OrderGroupId} during credit"); payment.TransactionID = result.TransactionNumber; payment.AcceptChanges(); success = true; Log.Info($"Successfully credited payment with ID:{currentPayment.Payment.Id} belonging to order with ID: {currentPayment.OrderGroupId}"); } if (_paymentCreditor != null) return _paymentCreditor.Credit(currentPayment) && success; return success; }
public bool Capture(PaymentMethod currentPayment, string additionalValues) { Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment; Log.InfoFormat("Capturing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); int transactionId; if (!int.TryParse(payment.AuthorizationCode, out transactionId)) { Log.ErrorFormat("Could not get PayEx transaction ID from payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); return(false); } Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId); long amount = payment.Amount.RoundToLong(); string orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber); CaptureResult result = _paymentManager.Capture(transactionId, amount, orderNumber, currentPayment.Payment.Vat, additionalValues); bool success = false; if (result.Success && !string.IsNullOrWhiteSpace(result.TransactionNumber)) { Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during capture", result.TransactionNumber, payment.Id, payment.OrderGroupId); payment.ValidationCode = result.TransactionNumber; PaymentStatusManager.ProcessPayment(payment); payment.AcceptChanges(); success = true; Log.InfoFormat("Successfully captured payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } if (_paymentCapturer != null) { return(_paymentCapturer.Capture(currentPayment) && success); } return(success); }
private bool UpdateOrderAddress(PaymentMethod currentPayment, TransactionResult transactionDetails2) { Log.InfoFormat("Updating order address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); if (!currentPayment.RequireAddressUpdate) { Log.InfoFormat("This payment method ({0}) does not require an order address update. Payment with ID:{1} belonging to order with ID: {2}", currentPayment.PaymentMethodCode, currentPayment.Payment.Id, currentPayment.OrderGroupId); return(true); } Address newAddress = currentPayment.GetAddressFromPayEx(transactionDetails2); if (newAddress == null) { return(false); } Cart cart = currentPayment.Cart; OrderAddress shippingAddress = GetShippingAddress(cart); if (shippingAddress == null) { Log.ErrorFormat("Could not update address for payment with ID:{0} belonging to order with ID: {1}. Reason: Shipping address was not found!", currentPayment.Payment.Id, currentPayment.OrderGroupId); return(false); } Dictionary <string, string> propertiesToUpdate = new Dictionary <string, string>() { { GetPropertyName(() => shippingAddress.FirstName), newAddress.FirstName }, { GetPropertyName(() => shippingAddress.LastName), newAddress.LastName }, { GetPropertyName(() => shippingAddress.Line1), newAddress.Line1 }, { GetPropertyName(() => shippingAddress.PostalCode), newAddress.PostCode }, { GetPropertyName(() => shippingAddress.City), newAddress.City }, { GetPropertyName(() => shippingAddress.CountryName), newAddress.Country }, { GetPropertyName(() => shippingAddress.Email), newAddress.Email }, }; bool updated = UpdatePropertyValues(shippingAddress, propertiesToUpdate); if (!string.IsNullOrWhiteSpace(newAddress.Fullname)) { Log.InfoFormat("Setting customer name of cart to {0} on payment with ID:{1} belonging to order with ID: {2}", newAddress.Fullname, currentPayment.Payment.Id, currentPayment.OrderGroupId); cart.CustomerName = newAddress.Fullname; } try { if (updated) { using (TransactionScope scope = new TransactionScope()) { shippingAddress.AcceptChanges(); cart.AcceptChanges(); scope.Complete(); } } return(true); } catch (Exception e) { Log.Error("Could not update address for payment. See next log statement for more information", e); Log.ErrorFormat("Could not update address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); return(false); } }
public bool Capture(PaymentMethod currentPayment) { return Capture(currentPayment, string.Empty); }
public override bool ProcessPayment(Mediachase.Commerce.Orders.Payment payment, ref string message) { Log.InfoFormat("Processing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); if (HttpContext.Current == null) { Log.ErrorFormat("HttpContent.Current is null"); return(false); } PaymentMethod currentPayment = _paymentMethodFactory.Create(payment); if (currentPayment == null) { Log.ErrorFormat("As the PaymentMethod for payment with ID:{0} could not be resolved, it cannot be processed by the PayEx Payment Provider!", payment.Id); return(false); } Log.InfoFormat("Successfully resolved the PaymentMethod for payment with ID:{0}. The PaymentMethodCode is {1}", payment.Id, currentPayment.PaymentMethodCode); if (currentPayment.IsPurchaseOrder) { Log.InfoFormat("Payment with ID:{0} is a purchase order. It's transaction type is {1}", payment.Id, payment.TransactionType); // when user click complete order in commerce manager the transaction type will be Capture if (currentPayment.IsCapture) { Log.InfoFormat("Begin CapturePayment for payment with ID:{0}", payment.Id); return(currentPayment.Capture()); } // When "Refund" shipment in Commerce Manager, this method will be invoked with the TransactionType is Credit if (currentPayment.IsCredit) { Log.InfoFormat("Begin CreditPayment for payment with ID:{0}", payment.Id); return(currentPayment.Credit()); } Log.ErrorFormat("The transaction type for payment with ID:{0} is {1}. The PayEx Payment Provider expected a Credit or Capture transaction type!", payment.Id, payment.TransactionType); return(false); } // When "Complete" or "Refund" shipment in Commerce Manager, this method will be run again with the TransactionType is Capture/Credit // PayEx will always return true to bypass the payment process again. if (!currentPayment.IsAuthorization) { Log.InfoFormat("The transaction type for payment with ID:{0} is {1}, meaning the payment process has already been run once.", payment.Id, payment.TransactionType); return(true); } if (!currentPayment.IsCart) { Log.ErrorFormat("Payment with ID:{0} is not a cart. That should not be possible at this stage!", payment.Id); return(false); } Log.InfoFormat("Initializing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); PaymentInitializeResult result = currentPayment.Initialize(); message = result.ErrorMessage ?? string.Empty; if (!result.Success) { Log.ErrorFormat("Could not initialize payment with ID:{0} belonging to order with ID: {1}. Message: {2}", payment.Id, payment.OrderGroupId, message); } else { Log.InfoFormat("Successfully initialized payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId); } return(result.Success); }
public bool Capture(PaymentMethod currentPayment) { return(Capture(currentPayment, string.Empty)); }