Beispiel #1
0
        /// <summary>
        /// At this time, Sezzle only allows configuration of the URL that we send our webhooks to.
        /// </summary>
        /// <remarks>
        ///     https://gateway.sezzle.com/v1/configuration
        /// </remarks>
        /// <returns></returns>
        public async Task <ConfigurationUpdateResponse> UpdateAsync(ConfigurationUpdateRequest configuration)
        {
            var tokenTask = _authenticationEndpoint.CreateTokenAsync();

            var requestUrl = UrlStringExtensions.FormatRequestUrl(_baseConfiguration.ApiUrl, "/configuration");

            var token    = await(tokenTask);
            var response = await _sezzleHttpClient.PostAsync <ConfigurationUpdateRequest, ConfigurationUpdateResponse>(token.Token, requestUrl, configuration);

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// If you pass 'true’ to 'merchant_completes’ in our Create CreateCheckoutRequest flow, then you must call our Complete CreateCheckoutRequest endpoint.
        /// For some checkouts, a merchant may need to have the user return to their site for additional steps before completing the purchase.
        /// If this is the case, the order completion endpoint is used to complete the CreateCheckoutRequest with Sezzle.
        /// From the time the user is redirected back to the Merchant’s site, you must make the request to complete the createCheckoutRequest within 30 minutes, or the createCheckoutRequest will be
        /// cancelled by Sezzle. If the createCheckoutRequest has expired, we will return the rejection response on the right, with a Status 409
        /// There are two non-error responses expected. Either an HTTP 200 (currently no response body) or a rejection message.
        /// </summary>
        /// <param name="completeCheckoutRequest"></param>
        /// <remarks>
        ///     https://gateway.sezzle.com/v1/checkouts/{order_reference_id}/complete
        /// </remarks>
        /// <returns></returns>
        public async Task <CompleteCheckoutResponse> CompleteAsync(CompleteCheckoutRequest completeCheckoutRequest)
        {
            var tokenTask = _authenticationEndpoint.CreateTokenAsync();

            //create url and request object
            var requestUrl = UrlStringExtensions.FormatRequestUrl(GetCheckoutsBaseUrl(), $"{completeCheckoutRequest.LocalOrderId}/complete");

            var token    = await tokenTask;
            var response = await _sezzleHttpClient.PostAsync <CompleteCheckoutRequest, CompleteCheckoutResponse>(token.Token, requestUrl, null);

            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Sezzle allows refunds for orders either through our Merchant Dashboard or through the API. If the refund is processed through the dashboard, a webhook will be sent to your system. In either case, Sezzle allows for either partial or complete refunds. RefundAsync amounts are relative to the order total, not the amount that has been paid by the shopper.
        /// </summary>
        /// <remarks>
        ///     https://gateway.sezzle.com/v1/orders/{order_reference_id}/refund
        /// </remarks>
        /// <param name="orderRefundRequest"></param>
        /// <returns></returns>
        public async Task <OrderRefundResponse> RefundAsync(OrderRefundRequest orderRefundRequest)
        {
            var tokenTask = _authenticationEndpoint.CreateTokenAsync();

            //build in the shipping information to true for all requests.  doesn't hurt to have it.
            var requestUrl = UrlStringExtensions.FormatRequestUrl(_baseConfiguration.ApiUrl, $"/orders/{orderRefundRequest.OrderReferenceId}/refund");

            var token = await tokenTask;
            //send null into the client; we have manually added the necessary request data to parameters and url.
            var response = await _sezzleHttpClient.PostAsync <OrderRefundRequestBody, OrderRefundResponse>(token.Token, requestUrl, orderRefundRequest, null);

            return(response);
        }
        public async Task <HealthCheckResponse> CheckHealthAsync(HealthCheckRequest request)
        {
            var tokenTask = _authenticationEndpoint.CreateTokenAsync();

            //create url and request object
            var requestUrl = UrlStringExtensions.FormatRequestUrl(_baseConfiguration.ApiUrl, "/healthz");

            var token = await tokenTask;

            //tokens are not needed to check the health, but is done here for simplicity of code reuse.
            var response = await _sezzleHttpClient.GetAsync <HealthCheckRequest, HealthCheckResponse>(token.Token, requestUrl, request);

            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// Attempts to retrieve a token by passing over the Sezzle configuration public and private keys
        /// </summary>
        /// <returns></returns>
        public async Task <AuthenticationResponse> CreateTokenAsync()
        {
            //create url and request object
            var requestUrl = UrlStringExtensions.FormatRequestUrl(_baseConfiguration.ApiUrl, "authentication");

            var authRequest = new AuthenticationRequest()
            {
                PrivateKey = _authenticationConfiguration.ApiPrivateKey,
                PublicKey  = _authenticationConfiguration.ApiPublicKey
            };

            //make request
            AuthenticationResponse resp = await _sezzleHttpClient.PostAsync <AuthenticationRequest, AuthenticationResponse>(null, requestUrl, authRequest);

            return(resp);
        }
Beispiel #6
0
 private string GetCheckoutsBaseUrl()
 {
     return(UrlStringExtensions.FormatRequestUrl(_baseConfiguration.ApiUrl, "/checkouts"));
 }