Пример #1
0
        /// <summary>
        /// Resource /{merchantId}/hostedcheckouts
        /// <a href="https://developer.globalcollect.com/documentation/api/server/#__merchantId__hostedcheckouts_post">Create hosted checkout</a>
        /// </summary>
        /// <param name="body">CreateHostedCheckoutRequest</param>
        /// <param name="context">CallContext</param>
        /// <returns>CreateHostedCheckoutResponse</returns>
        /// <exception cref="ValidationException">if the request was not correct and couldn't be processed (HTTP status code BadRequest)</exception>
        /// <exception cref="AuthorizationException">if the request was not allowed (HTTP status code Forbidden)</exception>
        /// <exception cref="IdempotenceException">if an idempotent request caused a conflict (HTTP status code Conflict)</exception>
        /// <exception cref="ReferenceException">if an object was attempted to be referenced that doesn't exist or has been removed,
        ///            or there was a conflict (HTTP status code NotFound, Conflict or Gone)</exception>
        /// <exception cref="GlobalCollectException">if something went wrong at the GlobalCollect platform,
        ///            the GlobalCollect platform was unable to process a message from a downstream partner/acquirer,
        ///            or the service that you're trying to reach is temporary unavailable (HTTP status code InternalServerError, BadGateway or ServiceUnavailable)</exception>
        /// <exception cref="ApiException">if the GlobalCollect platform returned any other error</exception>
        public async Task <CreateHostedCheckoutResponse> Create(CreateHostedCheckoutRequest body, CallContext context = null)
        {
            string uri = InstantiateUri("/{apiVersion}/{merchantId}/hostedcheckouts", null);

            try
            {
                return(await _communicator.Post <CreateHostedCheckoutResponse>(
                           uri,
                           ClientHeaders,
                           null,
                           body,
                           context));
            }
            catch (ResponseException e)
            {
                object errorObject;
                switch (e.StatusCode)
                {
                default:
                    errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body);
                    break;
                }
                throw CreateException(e.StatusCode, e.Body, errorObject, context);
            }
        }
Пример #2
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                HostedCheckoutSpecificInput hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput();
                hostedCheckoutSpecificInput.Locale  = "en_GB";
                hostedCheckoutSpecificInput.Variant = "testVariant";

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 2345L;
                amountOfMoney.CurrencyCode = "USD";

                Address billingAddress = new Address();
                billingAddress.CountryCode = "US";

                Customer customer = new Customer();
                customer.BillingAddress = billingAddress;

                Order order = new Order();
                order.AmountOfMoney = amountOfMoney;
                order.Customer      = customer;

                CreateHostedCheckoutRequest body = new CreateHostedCheckoutRequest();
                body.HostedCheckoutSpecificInput = hostedCheckoutSpecificInput;
                body.Order = order;

                CreateHostedCheckoutResponse response = await client.Merchant("merchantId").Hostedcheckouts().Create(body);
            }
#pragma warning restore 0168
        }
Пример #3
0
        /// <inheritdoc/>
        public async Task <CreateHostedCheckoutResponse> CreateHostedCheckout(CreateHostedCheckoutRequest body, CallContext context = null)
        {
            string uri = InstantiateUri("/v2/{merchantId}/hostedcheckouts", null);

            try
            {
                return(await _communicator.Post <CreateHostedCheckoutResponse>(
                           uri,
                           ClientHeaders,
                           null,
                           body,
                           context)
                       .ConfigureAwait(false));
            }
            catch (ResponseException e)
            {
                object errorObject = _communicator.Unmarshal <ErrorResponse>(e.Body);
                throw CreateException(e.StatusCode, e.Body, errorObject, context);
            }
        }
Пример #4
0
        public IPaymentResponse Charge(PaymentRequest request)
        {
            RedirectResponse res = null;

            if (Setting == null)
            {
                return(res);
            }

            var ogoneApi = new OgoneApi(Setting);

            var checkoutRequest = new CreateHostedCheckoutRequest
            {
                Order = new Order
                {
                    AmountOfMoney = new AmountOfMoney
                    {
                        Amount       = (request.TotalAmount * 100).ToString("0"),
                        CurrencyCode = request.Currency
                    },
                    Customer = new Customer
                    {
                        BillingAddress = new Address
                        {
                            CountryCode = request.Country
                        },
                        MerchantCustomerId = Name
                    }
                }
            };
            var result = ogoneApi.Hostedcheckouts(checkoutRequest);

            if (result != null)
            {
                res = new RedirectResponse(string.Format("{0}.{1}", Setting.BaseUrl(), result.PartialRedirectUrl), request.Id);
            }
            return(res);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="customerPayment"></param>
        /// <param name="returnUrl">The URL that the user will be redirected to after the payment process.</param>
        /// <returns></returns>
        public async Task <string> CreateHostedCheckoutAsync(Entities.Customer customer, Entities.CustomerPayment customerPayment, string returnUrl)
        {
            var result = string.Empty;

            using (Client client = GetClient())
            {
                var ingenicoSettings      = _configuration.GetSection("Ingenico");
                var merchantId            = ingenicoSettings.GetValue <string>("MerchantID");
                var hostedCheckoutVariant = ingenicoSettings.GetValue <string>("HostedCheckoutVariant");
                var currency = string.IsNullOrEmpty(customerPayment.Currency) ? ingenicoSettings.GetValue <string>("DefaultCurrency") : customerPayment.Currency;
                var locale   = string.IsNullOrEmpty(customer.Locale) ? ingenicoSettings.GetValue <string>("DefaultLocale") : customer.Locale;

                var hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput
                {
                    IsRecurring           = false,
                    Locale                = locale,
                    Variant               = hostedCheckoutVariant,
                    ReturnCancelState     = true,
                    PaymentProductFilters = new PaymentProductFiltersHostedCheckout()
                    {
                        // Only allow certain payment methods
                        RestrictTo = new PaymentProductFilter
                        {
                            Products = PaymentProductIncludeIds
                        }
                    }
                };

                var amountOfMoney = new AmountOfMoney
                {
                    Amount       = ConvertToIngenicoAmount(customerPayment.Total == 0 ? 0.01m : customerPayment.Total), // Amount cannot be zero. Amount has to be at least 1 cent.
                    CurrencyCode = currency
                };

                var order = new Order
                {
                    Customer      = CreateIngenicoCustomer(customer),
                    AmountOfMoney = amountOfMoney,
                    References    = new OrderReferences
                    {
                        // Update Order with CustomerPayment Id as reference
                        MerchantReference = customerPayment.MerchantReference.ToString()
                    }
                };

                // Create Hosted Checkout for recurring monthly direct debit via credit card or Sepa direct debit payment methods for subscription purchase

                var cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInputBase
                {
                    Tokenize  = true,
                    Recurring = new CardRecurrenceDetails
                    {
                        RecurringPaymentSequenceIndicator = "first"
                    },
                    AuthorizationMode = "SALE",
                    RequiresApproval  = false
                };

                var sepaDirectDebitPaymentMethodSpecificInput = new SepaDirectDebitPaymentMethodSpecificInputBase()
                {
                    PaymentProduct771SpecificInput = new SepaDirectDebitPaymentProduct771SpecificInputBase()
                    {
                        Mandate = new CreateMandateBase()
                        {
                            CustomerReference = order.Customer.MerchantCustomerId,
                            RecurrenceType    = "RECURRING",
                            SignatureType     = "SMS"
                        },
                    }
                };

                var body = new CreateHostedCheckoutRequest
                {
                    HostedCheckoutSpecificInput = hostedCheckoutSpecificInput,
                    Order = order,
                    CardPaymentMethodSpecificInput            = cardPaymentMethodSpecificInput,
                    SepaDirectDebitPaymentMethodSpecificInput = sepaDirectDebitPaymentMethodSpecificInput
                };

                try
                {
                    // Initial call to Ingenico API to create hosted checkout.
                    CreateHostedCheckoutResponse createHostedCheckoutResponse = await client.Merchant(merchantId).Hostedcheckouts().Create(body);

                    if (createHostedCheckoutResponse.MerchantReference == customerPayment.MerchantReference.ToString())
                    {
                        // Do initial call to Ingenico API to retreive status of payment
                        GetHostedCheckoutResponse getHostedCheckoutResponse = await client.Merchant(merchantId).Hostedcheckouts().Get(createHostedCheckoutResponse.HostedCheckoutId);

                        // Update CustomerPayment record
                        customerPayment.Status = getHostedCheckoutResponse.Status;
                        //_customerPaymentRepository.Update(customerPayment);
                    }

                    // Build up redirect URL
                    var subdomain = ingenicoSettings.GetValue <string>("Subdomain");
                    result = $"{subdomain}{createHostedCheckoutResponse.PartialRedirectUrl}";
                }
                catch (Exception ex)
                {
                    //Logger.Error("Exception at : PaymentManager.CreateHostedCheckout\n", ex);

                    // Delete Customer Payment records, since initial payment failed
                    //_customerPaymentRepository.Delete(customerPayment.Id);
                }
            }

            return(result);
        }
Пример #6
0
        public virtual IActionResult HostedCheckoutCreate([FromRoute][Required] string merchantId, [FromBody] CreateHostedCheckoutRequest createHostedCheckoutRequest)
        {
            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(CreateHostedCheckoutResponse));

            //TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(400, default(CreateHostedCheckoutResponse));

            string exampleJson = null;

            exampleJson = "{\n  \"hostedCheckoutId\" : \"hostedCheckoutId\",\n  \"partialRedirectUrl\" : \"partialRedirectUrl\",\n  \"returnmac\" : \"returnmac\",\n  \"merchantReference\" : \"merchantReference\",\n  \"invalidTokens\" : [ \"invalidTokens\", \"invalidTokens\" ]\n}";

            var example = exampleJson != null
            ? JsonConvert.DeserializeObject <CreateHostedCheckoutResponse>(exampleJson)
            : default(CreateHostedCheckoutResponse);

            //TODO: Change the data returned
            return(new ObjectResult(example));
        }
Пример #7
0
        public IPaymentResponse Charge(PaymentRequest request)
        {
            RedirectResponse res = null;
            var additional       = new Dictionary <string, object>(request.Additional, StringComparer.OrdinalIgnoreCase);

            var variant    = GetValue(additional, "variant", null);
            var locale     = GetValue(additional, "locale", null);
            var paymentIds = GetValue(additional, "paymentIds", null);

            if (Setting == null)
            {
                return(res);
            }

            var ogoneApi = new OgoneApi(Setting);
            PaymentProductFiltersHostedCheckout PaymentProductFilters = null;

            if (paymentIds != null)
            {
                PaymentProductFilters = new PaymentProductFiltersHostedCheckout
                {
                    RestrictTo = new PaymentProductFilter
                    {
                        Products = paymentIds.Split(',').Select(Int32.Parse).ToList()
                    }
                };
            }

            var checkoutRequest = new CreateHostedCheckoutRequest
            {
                Order = new Order
                {
                    AmountOfMoney = new AmountOfMoney
                    {
                        Amount       = (request.TotalAmount * 100).ToString("0"),
                        CurrencyCode = request.Currency
                    },
                    Customer = new Customer
                    {
                        BillingAddress = new Address
                        {
                            CountryCode = request.Country
                        },
                        MerchantCustomerId = Name
                    }
                }
            };

            if (Setting.ReturnUrl != null)
            {
                checkoutRequest.HostedCheckoutSpecificInput = new HostedCheckoutSpecificInput
                {
                    ReturnUrl = Setting.ReturnUrl
                };
            }

            var result = ogoneApi.Hostedcheckouts(checkoutRequest);

            if (result != null)
            {
                res = new RedirectResponse(string.Format("{0}.{1}", Setting.BaseUrl(), result.PartialRedirectUrl), request.Id);
                request.ReferenceId = result.HostedCheckoutId;
            }

            return(res);
        }