public bool Capture(PaymentMethod currentPayment) { 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, string.Empty); 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; 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 void UpdateConsumerInformation(PaymentMethod paymentMethod, ConsumerLegalAddressResult consumerLegalAddress) { Log.InfoFormat("Updating consumer information for payment with ID:{0} belonging to order with ID: {1}", paymentMethod.Payment.Id, paymentMethod.OrderGroupId); if (!(paymentMethod.Payment is ExtendedPayExPayment)) { Log.ErrorFormat("Payment with ID:{0} belonging to order with ID: {1} is not an ExtendedPayExPayment, cannot update consumer information", paymentMethod.Payment.Id, paymentMethod.OrderGroupId); return; } ExtendedPayExPayment payment = paymentMethod.Payment as ExtendedPayExPayment; try { using (TransactionScope scope = new TransactionScope()) { payment.FirstName = consumerLegalAddress.FirstName; payment.LastName = consumerLegalAddress.LastName; payment.StreetAddress = consumerLegalAddress.Address; payment.PostNumber = consumerLegalAddress.PostNumber; payment.City = consumerLegalAddress.City; payment.CountryCode = consumerLegalAddress.Country; payment.AcceptChanges(); scope.Complete(); Log.InfoFormat("Successfully updated consumer information for payment with ID:{0} belonging to order with ID: {1}", paymentMethod.Payment.Id, paymentMethod.OrderGroupId); } } catch (Exception e) { Log.Error("Could not update consumer information. See next log item for more information", e); Log.ErrorFormat( "Could not update consumer information for payment with ID:{0}. ConsumerLegalAddressResult:{1}.", payment.Id, consumerLegalAddress); } }
public void UpdatePaymentInformation(PaymentMethod paymentMethod, string authorizationCode, string paymentMethodCode) { try { Log.InfoFormat("Updating payment information for payment with ID:{0} belonging to order with ID: {1}", paymentMethod.Payment.Id, paymentMethod.OrderGroupId); if (string.IsNullOrWhiteSpace(paymentMethodCode)) { paymentMethodCode = paymentMethod.PaymentMethodCode; } using (TransactionScope scope = new TransactionScope()) { Log.InfoFormat("Setting authorization code:{0} for payment with ID:{1} belonging to order with ID: {2}", authorizationCode, paymentMethod.Payment.Id, paymentMethod.OrderGroupId); Log.InfoFormat("Setting payment method code:{0} for payment with ID:{1} belonging to order with ID: {2}", paymentMethodCode, paymentMethod.Payment.Id, paymentMethod.OrderGroupId); ((Mediachase.Commerce.Orders.Payment)paymentMethod.Payment).AuthorizationCode = authorizationCode; ((Mediachase.Commerce.Orders.Payment)paymentMethod.Payment).AcceptChanges(); paymentMethod.OrderGroup.OrderForms[0]["PaymentMethodCode"] = paymentMethodCode; paymentMethod.OrderGroup.AcceptChanges(); scope.Complete(); } } catch (Exception e) { Log.Error("Could not update payment information. See next log item for more information.", e); Log.ErrorFormat("Could not update payment information for orderForm with ID:{0}. AuthorizationCode:{1}. PaymentMethodCode:{2}", paymentMethod.OrderGroup.OrderForms[0].Id, authorizationCode, paymentMethodCode); } }
public void SetPaymentProcessed(PaymentMethod paymentMethod) { var payment = (Mediachase.Commerce.Orders.Payment) paymentMethod.Payment; PaymentStatusManager.ProcessPayment(payment); payment.AcceptChanges(); Log.InfoFormat("Successfully set payment status to pros for payment with ID:{0} belonging to order with ID: {1}", paymentMethod.Payment.Id, paymentMethod.OrderGroupId); }
private CustomerDetails CreateModel(PaymentMethod currentPayment) { if (!(currentPayment.Payment is ExtendedPayExPayment)) return null; ExtendedPayExPayment payment = currentPayment.Payment as ExtendedPayExPayment; return new CustomerDetails { SocialSecurityNumber = payment.SocialSecurityNumber, CountryCode = payment.CountryCode, }; }
private PaymentInformation CreateModel(PaymentMethod currentPayment, string orderNumber) { var additionalValues = FormatAdditionalValues(currentPayment); var priceArgsList = _parameterReader.GetPriceArgsList(currentPayment.PaymentMethodDto); var purchaseOperation = currentPayment.PurchaseOperation.ToString(); return new PaymentInformation( currentPayment.Cart.Total.RoundToLong(), priceArgsList, currentPayment.Cart.BillingCurrency, currentPayment.Payment.Vat, orderNumber, currentPayment.Payment.ProductNumber, currentPayment.Payment.Description, currentPayment.Payment.ClientIpAddress, additionalValues, currentPayment.Payment.ReturnUrl, currentPayment.DefaultView, currentPayment.Payment.CancelUrl, ContentLanguage.PreferredCulture.TextInfo.CultureName, purchaseOperation); }
public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef) { PaymentInitializeResult result = new PaymentInitializeResult(); Log.InfoFormat("Begin redirect to PayEx for payment with ID:{0} belonging to order with ID: {1}.", currentPayment.Payment.Id, currentPayment.OrderGroupId); if (!string.IsNullOrWhiteSpace(returnUrl)) { Log.InfoFormat("Redirecting user PayEx for payment with ID:{0} belonging to order with ID: {1}. ReturnUrl: {2}", currentPayment.Payment.Id, currentPayment.OrderGroupId, returnUrl); HttpContext.Current.Response.Redirect(returnUrl, true); result.Success = true; return result; } Log.ErrorFormat("Could not redirect user to PayEx for payment with ID:{0} belonging to order with ID: {1}. ReturnUrl was empty!", currentPayment.Payment.Id, currentPayment.OrderGroupId); return result; }
public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef) { Log.InfoFormat("Retrieving consumer legal address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); CustomerDetails customerDetails = CreateModel(currentPayment); if (customerDetails == null) throw new Exception("Payment class must be ExtendedPayExPayment when using this payment method"); ConsumerLegalAddressResult result = _verificationManager.GetConsumerLegalAddress(customerDetails.SocialSecurityNumber, customerDetails.CountryCode); if (!result.Status.Success) return new PaymentInitializeResult { ErrorMessage = result.Status.Description }; _paymentActions.UpdateConsumerInformation(currentPayment, result); Log.InfoFormat("Successfully retrieved consumer legal address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); return _paymentInitializer.Initialize(currentPayment, orderNumber, returnUrl, orderRef); }
private string FormatAdditionalValues(PaymentMethod currentPayment) { var staticAdditionalValues = _parameterReader.GetAdditionalValues(currentPayment.PaymentMethodDto); var stringBuilder = new StringBuilder(staticAdditionalValues); var dynamicAdditionalValues = _additionalValuesFormatter.Format(currentPayment.Payment as PayExPayment); if (!string.IsNullOrWhiteSpace(dynamicAdditionalValues)) { if (!string.IsNullOrWhiteSpace(staticAdditionalValues)) stringBuilder.Append("&"); stringBuilder.Append(dynamicAdditionalValues); } return stringBuilder.ToString(); }
public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef) { Log.InfoFormat("Calling PurchasePartPaymentSale for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); CustomerDetails customerDetails = CreateModel(currentPayment); if (customerDetails == null) throw new Exception("Payment class must be ExtendedPayExPayment when using this payment method"); PurchasePartPaymentSaleResult result = _paymentManager.PurchasePartPaymentSale(orderRef, customerDetails); if (!result.Status.Success) return new PaymentInitializeResult { ErrorMessage = result.Status.Description }; _paymentActions.UpdatePaymentInformation(currentPayment, result.TransactionNumber, result.PaymentMethod); Log.InfoFormat("Successfully called PurchasePartPaymentSale for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); return new PaymentInitializeResult { Success = true }; }
public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef) { Log.Info($"Initializing payment with ID:{currentPayment.Payment.Id} belonging to order with ID: {currentPayment.OrderGroupId}"); var paymentInformation = CreateModel(currentPayment, orderNumber); var result = _paymentManager.Initialize(currentPayment.Cart, paymentInformation, currentPayment.IsDirectModel, currentPayment.IsDirectModel); if (!result.Status.Success) return new PaymentInitializeResult { Success = false, ErrorMessage = result.Status.Description }; Log.Info($"Setting PayEx order reference to {result.OrderRef} on payment with ID:{currentPayment.Payment.Id} belonging to order with ID: {currentPayment.OrderGroupId}"); currentPayment.Payment.PayExOrderRef = result.OrderRef.ToString(); _cartActions.UpdateCartInstanceId(currentPayment.Cart); // Save all the changes that have been done to the cart if (_paymentInitializer != null) return _paymentInitializer.Initialize(currentPayment, orderNumber, result.RedirectUrl, result.OrderRef.ToString()); return new PaymentInitializeResult { Success = true }; }
public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef) { Log.InfoFormat("Generating order number for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); if (string.IsNullOrWhiteSpace(orderNumber)) orderNumber = _orderNumberGenerator.Generate(currentPayment.Cart); Log.InfoFormat("Generated order number:{0} for payment with ID:{1} belonging to order with ID: {2}", orderNumber, currentPayment.Payment.Id, currentPayment.OrderGroupId); currentPayment.Payment.OrderNumber = orderNumber; if (!string.IsNullOrWhiteSpace(currentPayment.Payment.Description)) { if (currentPayment.Payment.Description.Contains("{0}")) { Log.InfoFormat("Including the ordernumber in the payment description for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); currentPayment.Payment.Description = string.Format(currentPayment.Payment.Description, orderNumber); Log.InfoFormat("Payment description is set to:{0} for payment with ID:{1} belonging to order with ID: {2}", currentPayment.Payment.Description, currentPayment.Payment.Id, currentPayment.OrderGroupId); } } Log.InfoFormat("Finished generating order number for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); return _initializer.Initialize(currentPayment, orderNumber, returnUrl, orderRef); }
private CustomerDetails CreateModel(PaymentMethod currentPayment) { if (!(currentPayment.Payment is ExtendedPayExPayment)) return null; ExtendedPayExPayment payment = currentPayment.Payment as ExtendedPayExPayment; return new CustomerDetails { SocialSecurityNumber = payment.SocialSecurityNumber, FirstName = payment.FirstName, LastName = payment.LastName, StreetAddress = payment.StreetAddress, City = payment.City, CoAddress = payment.CoAddress, CountryCode = payment.CountryCode, Email = payment.Email, IpAddress = currentPayment.Payment.ClientIpAddress, MobilePhone = payment.MobilePhone, PostNumber = payment.PostNumber, }; }
public PaymentCompleteResult Complete(PaymentMethod currentPayment, string orderRef) { PaymentCompleteResult result = new PaymentCompleteResult() { Success = false }; if (currentPayment.RequireAddressUpdate) { Log.Info("MasterPass is using best practice flow"); Log.InfoFormat("Finalizing transaction for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); var total = currentPayment.Cart.Total.RoundToLong(); var totalVat = currentPayment.Cart.TaxTotal.RoundToLong(); var finalizeTransactionResult = _paymentManager.FinalizeTransaction(orderRef, total, totalVat, currentPayment.Payment.ClientIpAddress); if (!finalizeTransactionResult.Success) { Log.InfoFormat( "Finalize transaction failed for payment with ID:{0} belonging to order with ID: {1}. Reason ErrorCode: {2} Description: {3}", currentPayment.Payment.Id, currentPayment.OrderGroupId, finalizeTransactionResult.Status.ErrorCode, finalizeTransactionResult.Status.Description); return result; } Log.InfoFormat( "Successfully called finalize transaction for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } else { Log.Info("MasterPass is using redirect flow"); } if (_paymentCompleter != null) result = _paymentCompleter.Complete(currentPayment, orderRef); return result; }
public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef) { if (currentPayment.RequireAddressUpdate) { Log.InfoFormat( "Retrieving consumer legal address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); CustomerDetails customerDetails = CreateModel(currentPayment); if (customerDetails == null) throw new Exception("Payment class must be ExtendedPayExPayment when using this payment method"); var result = _paymentManager.GetAddressByPaymentMethod(currentPayment.PaymentMethodCode, customerDetails.SocialSecurityNumber, customerDetails.PostNumber, customerDetails.CountryCode, customerDetails.IpAddress); if (!result.Status.Success) return new PaymentInitializeResult {ErrorMessage = result.Status.Description}; var convertToConsumerAddress = ConvertToConsumerAddress(result); _paymentActions.UpdateConsumerInformation(currentPayment, convertToConsumerAddress); var extendedPayment = currentPayment.Payment as ExtendedPayExPayment; _updateAddressHandler.UpdateAddress(currentPayment.Cart, extendedPayment); Log.InfoFormat( "Successfully retrieved consumer legal address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } else { Log.InfoFormat( "Payment method is configured to not use consumer legal address for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); } return _paymentInitializer.Initialize(currentPayment, orderNumber, returnUrl, orderRef); }
public PaymentCompleteResult Complete(PaymentMethod currentPayment, string orderRef) { Log.InfoFormat("Completing payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); CompleteResult completeResult = _paymentManager.Complete(orderRef); if (!completeResult.Success || string.IsNullOrWhiteSpace(completeResult.TransactionNumber)) return new PaymentCompleteResult { TransactionErrorCode = completeResult.ErrorDetails != null ? completeResult.ErrorDetails.TransactionErrorCode : string.Empty }; if (completeResult.GetTransactionDetails) { Log.InfoFormat("Retrieving transaction details for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); if (_paymentCompleter == null) _paymentCompleter = new UpdateTransactionDetails(null, _paymentManager); _paymentCompleter = new UpdateTransactionDetails(_paymentCompleter, _paymentManager); } _paymentActions.UpdatePaymentInformation(currentPayment, completeResult.TransactionNumber, completeResult.PaymentMethod); PaymentCompleteResult result = new PaymentCompleteResult { Success = true }; if (_paymentCompleter != null) result = _paymentCompleter.Complete(currentPayment, orderRef); Log.InfoFormat("Successfully completed payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId); return result; }