private ReadOnlyCollection <PaymentOption> GetPaymentOptions(string shopName) { var paymentService = new PaymentServiceProvider(); var request = new GetPaymentOptionsRequest(shopName); return(paymentService.GetPaymentOptions(request).PaymentOptions); }
/// <summary> /// Initializes a new instance of the <see cref="PaymentManager" /> class. /// </summary> /// <param name="paymentServiceProvider">The payment service provider.</param> /// <param name="cartManager">The cart manager.</param> public PaymentManager([NotNull] PaymentServiceProvider paymentServiceProvider, [NotNull] CartManager cartManager) { Assert.ArgumentNotNull(paymentServiceProvider, "paymentServiceProvider"); this.PaymentServiceProvider = paymentServiceProvider; this.CartManager = cartManager; }
public PaymentManager(PaymentServiceProvider paymentServiceProvider, CartManager cartManager, StorefrontContext storefrontContext) { Assert.ArgumentNotNull(paymentServiceProvider, nameof(paymentServiceProvider)); PaymentServiceProvider = paymentServiceProvider; CartManager = cartManager; StorefrontContext = storefrontContext; }
public ManagerResponse <PaymentClientTokenResult, string> GetPaymentClientToken() { var request = new ServiceProviderRequest(); var result = PaymentServiceProvider.RunPipeline <ServiceProviderRequest, PaymentClientTokenResult>("commerce.payments.getClientToken", request); result.WriteToSitecoreLog(); return(new ManagerResponse <PaymentClientTokenResult, string>(result, result.ClientToken)); }
public PaymentManager( IConnectServiceProvider connectServiceProvider, IPaymentMapper paymentMapper, ILogService <CommonLog> logService) : base(logService) { Assert.ArgumentNotNull(connectServiceProvider, nameof(connectServiceProvider)); Assert.ArgumentNotNull(paymentMapper, nameof(paymentMapper)); this.paymentServiceProvider = connectServiceProvider.GetPaymentServiceProvider(); this.paymentMapper = paymentMapper; }
public PaymentManagerTests() { var connectServiceProvider = Substitute.For <IConnectServiceProvider>(); var logService = Substitute.For <ILogService <CommonLog> >(); var paymentMapper = Substitute.For <IPaymentMapper>(); this.paymentServiceProvider = Substitute.For <PaymentServiceProvider>(); connectServiceProvider.GetPaymentServiceProvider().Returns(this.paymentServiceProvider); this.fixture = new Fixture().Customize(new OmitOnRecursionCustomization()); this.paymentManager = Substitute.For <PaymentManager>(connectServiceProvider, paymentMapper, logService); }
private ReadOnlyCollection <PaymentMethod> GetPaymentMethods(PaymentOption paymentOption, Cart cart) { var paymentService = new PaymentServiceProvider(); var request = new GetPaymentMethodsRequest(paymentOption, cart.ShopName); var shippingParty = cart.Parties.FirstOrDefault(x => (string)x.Properties["Name"] == Constants.DefaultShipmentAddressName); if (shippingParty != null) { request.Properties["Country"] = shippingParty.Country; } return(paymentService.GetPaymentMethods(request).PaymentMethods); }
public ActionResult Index() { var paymentServiceProvider = new PaymentServiceProvider(); var request = new ServiceProviderRequest(); request.SetShopName("CommerceEngineDefaultStorefront"); request.CurrencyCode = "EUR"; var result = paymentServiceProvider.RunPipeline <ServiceProviderRequest, PaymentClientTokenResult>( "commerce.payments.getClientToken", request); return(View(result)); }
private ReadOnlyCollection <PaymentPrice> GetPaymentMethodPrices(ReadOnlyCollection <PaymentMethod> paymentMethods, Cart cart) { var paymentLookupList = new List <PaymentLookup>(); foreach (var paymentMethod in paymentMethods) { paymentLookupList.Add(new PaymentLookup() { MethodId = paymentMethod.PaymentOptionId }); } var paymentService = new PaymentServiceProvider(); var request = new GetPricesForPaymentsRequest(cart.ShopName, paymentLookupList, cart); return(paymentService.GetPricesForPayments(request).PaymentPrices); }
/// <summary> /// Initializes a new instance of the <see cref="CheckoutService"/> class. /// </summary> /// <param name="shippingServiceProvider">The shipping service provider.</param> /// <param name="paymentServiceProvider">The payment service provider.</param> /// <param name="customerServiceProvider">The customer service provider.</param> /// <param name="cartService">The cart service.</param> /// <param name="shopName">The shop name.</param> public CheckoutService( [NotNull] ShippingServiceProvider shippingServiceProvider, [NotNull] PaymentServiceProvider paymentServiceProvider, [NotNull] CustomerServiceProvider customerServiceProvider, [NotNull] ICartService cartService, [NotNull] string shopName) { Assert.ArgumentNotNull(shippingServiceProvider, "shippingServiceProvider"); Assert.ArgumentNotNull(paymentServiceProvider, "paymentServiceProvider"); Assert.ArgumentNotNull(customerServiceProvider, "customerServiceProvider"); Assert.ArgumentNotNull(cartService, "cartService"); Assert.ArgumentNotNullOrEmpty(shopName, "shopName"); this._shippingServiceProvider = shippingServiceProvider; this._paymentServiceProvider = paymentServiceProvider; this._customerServiceProvider = customerServiceProvider; this._cartService = cartService; this.shopName = shopName; }
public ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> > GetPaymentMethods(string userId, PaymentOption paymentOption) { Assert.ArgumentNotNull(paymentOption, nameof(paymentOption)); var result = new GetPaymentMethodsResult { Success = false }; var cartResult = CartManager.GetCart(userId); if (!cartResult.ServiceProviderResult.Success || cartResult.Result == null) { result.SystemMessages.ToList().AddRange(cartResult.ServiceProviderResult.SystemMessages); return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >(result, null)); } var request = new GetPaymentMethodsRequest(cartResult.Result, paymentOption); result = PaymentServiceProvider.GetPaymentMethods(request); result.WriteToSitecoreLog(); return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >(result, result.PaymentMethods.ToList())); }
public ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> > GetPaymentOptions(string userId) { var result = new GetPaymentOptionsResult { Success = false }; var cartResult = CartManager.GetCart(userId); if (!cartResult.ServiceProviderResult.Success || cartResult.Result == null) { result.SystemMessages.ToList().AddRange(cartResult.ServiceProviderResult.SystemMessages); return(new ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> >(result, null)); } if (StorefrontContext.Current == null) { throw new InvalidOperationException("Cannot be called without a valid storefront context."); } var request = new GetPaymentOptionsRequest(StorefrontContext.Current.ShopName, cartResult.Result); result = PaymentServiceProvider.GetPaymentOptions(request); result.WriteToSitecoreLog(); return(new ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> >(result, result.PaymentOptions.ToList())); }
public PaymentManager(IConnectServiceProvider connectServiceProvider) { Assert.ArgumentNotNull(connectServiceProvider, nameof(connectServiceProvider)); this.paymentServiceProvider = connectServiceProvider.GetPaymentServiceProvider(); }
public ActionResult RequestPayment() { // If you are OK with calling a uCommerce API at this point, you can simply call: // --- BEGIN uCommerce API. // TransactionLibrary.RequestPayments(); // return Redirect("/confirmation"); // This line is only required when using the DefaultPaymentMethod for the demo store. // --- END uCommerce API. // If you want to use the FederatedPayment parts of Commerce Connect. This is what you need to do, to make it work var cart = GetCart(); // For this demo store, it is assumed, that there is only one payment info associated with the order. // 1. You need to get the payment service URL for the payment var paymentService = new PaymentServiceProvider(); var baseUrl = HttpUtility.UrlDecode(paymentService.GetPaymentServiceUrl(new GetPaymentServiceUrlRequest()).Url) ?? string.Empty; // 2. You then need to add the payment method id and the payment id to the Url returned from the service. var paymentInfo = cart.Payment.First(); var completeUrl = string.Format(baseUrl, paymentInfo.PaymentMethodID, paymentInfo.ExternalId); // 3. In an IFrame set the url to the url from step 2. // Because this is a demo store, there is no actual payment gateway involved // Therefore at this point we need to manually set the status of the payment to Authorized. // ONLY CALLED FOR DEMO PURPOSES SetPaymentStatusToAuthorized(paymentInfo.ExternalId); // You should redirect the IFrame to the "completeUrl". // If you have configured your payment method to run the Checkout pipeline, // upon completion, then you do not need to do anything else. // The uCommerce framework takes care of the rest. // It checks that the transaction was authorized, and it redirects the customer to the accept url. // And it calls the Commerce Connect. SubmitVisitorOrder pipeline. // So you are done! // If you insist on doing the payment in the full Commerce Connect experience, // you should configure the uCommerce payment method to not run any pipeline on completion. // And in that case, you need to check that the payment was OK, and do the SubmitVisitorOrder calls yourself. // These steps are described below. // 4. When you believe that the transaction has been completed on the hosted page, you need to check if the payment is OK. // In the uCommerce implementation of the Commerce Connect API, this is done by passing the payment id as the access code. var actionResult = paymentService.GetPaymentServiceActionResult(new GetPaymentServiceActionResultRequest() { PaymentAcceptResultAccessCode = paymentInfo.ExternalId }); var paymentWasOk = actionResult.AuthorizationResult == "OK"; // 5. If the payment is OK, then you can Submit the Order. This corresponds to running the "Checkout" pipeline in uCommerce. if (paymentWasOk) { var orderService = new OrderServiceProvider(); var request = new SubmitVisitorOrderRequest(cart); orderService.SubmitVisitorOrder(request); } return(Redirect("/confirmation")); }