Esempio n. 1
0
        /// <summary>
        /// Resource /{merchantId}/payouts/{payoutId}/approve
        /// <a href="https://developer.globalcollect.com/documentation/api/server/#__merchantId__payouts__payoutId__approve_post">Approve payout</a>
        /// </summary>
        /// <param name="payoutId">string</param>
        /// <param name="body">ApprovePayoutRequest</param>
        /// <param name="context">CallContext</param>
        /// <returns>PayoutResponse</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 <PayoutResponse> Approve(string payoutId, ApprovePayoutRequest body, CallContext context = null)
        {
            IDictionary <string, string> pathContext = new Dictionary <string, string>();

            pathContext.Add("payoutId", payoutId);
            string uri = InstantiateUri("/{apiVersion}/{merchantId}/payouts/{payoutId}/approve", pathContext);

            try
            {
                return(await _communicator.Post <PayoutResponse>(
                           uri,
                           ClientHeaders,
                           null,
                           body,
                           context));
            }
            catch (ResponseException e)
            {
                object errorObject;
                switch (e.StatusCode)
                {
                case HttpStatusCode.PaymentRequired:
                    errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body);
                    break;

                default:
                    errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body);
                    break;
                }
                throw CreateException(e.StatusCode, e.Body, errorObject, context);
            }
        }
Esempio n. 2
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                ApprovePayoutRequest body = new ApprovePayoutRequest();
                body.DatePayout = "20150102";

                PayoutResponse response = await client.Merchant("merchantId").Payouts().Approve("payoutId", body);
            }
#pragma warning restore 0168
        }
        public async Task <IActionResult> ApprovePayout(string storeId, string payoutId, ApprovePayoutRequest approvePayoutRequest, CancellationToken cancellationToken = default)
        {
            using var ctx = _dbContextFactory.CreateContext();
            ctx.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            var revision = approvePayoutRequest?.Revision;

            if (revision is null)
            {
                ModelState.AddModelError(nameof(approvePayoutRequest.Revision), "The `revision` property is required");
            }
            if (!ModelState.IsValid)
            {
                return(this.CreateValidationError(ModelState));
            }
            var payout = await ctx.Payouts.GetPayout(payoutId, storeId, true, true);

            if (payout is null)
            {
                return(PayoutNotFound());
            }
            RateResult rateResult = null;

            try
            {
                rateResult = await _pullPaymentService.GetRate(payout, approvePayoutRequest?.RateRule, cancellationToken);

                if (rateResult.BidAsk == null)
                {
                    return(this.CreateAPIError("rate-unavailable", $"Rate unavailable: {rateResult.EvaluatedRule}"));
                }
            }
            catch (FormatException)
            {
                ModelState.AddModelError(nameof(approvePayoutRequest.RateRule), "Invalid RateRule");
                return(this.CreateValidationError(ModelState));
            }
            var ppBlob = payout.PullPaymentData.GetBlob();
            var cd     = _currencyNameTable.GetCurrencyData(ppBlob.Currency, false);
            var result = await _pullPaymentService.Approve(new PullPaymentHostedService.PayoutApproval()
            {
                PayoutId = payoutId,
                Revision = revision.Value,
                Rate     = rateResult.BidAsk.Ask
            });

            var errorMessage = PullPaymentHostedService.PayoutApproval.GetErrorMessage(result);

            switch (result)
            {
            case PullPaymentHostedService.PayoutApproval.Result.Ok:
                return(Ok(ToModel(await ctx.Payouts.GetPayout(payoutId, storeId, true), cd)));

            case PullPaymentHostedService.PayoutApproval.Result.InvalidState:
                return(this.CreateAPIError("invalid-state", errorMessage));

            case PullPaymentHostedService.PayoutApproval.Result.TooLowAmount:
                return(this.CreateAPIError("amount-too-low", errorMessage));

            case PullPaymentHostedService.PayoutApproval.Result.OldRevision:
                return(this.CreateAPIError("old-revision", errorMessage));

            case PullPaymentHostedService.PayoutApproval.Result.NotFound:
                return(PayoutNotFound());

            default:
                throw new NotSupportedException();
            }
        }
        public async Task <PayoutData> ApprovePayout(string storeId, string payoutId, ApprovePayoutRequest request, CancellationToken cancellationToken = default)
        {
            var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}", bodyPayload : request, method : HttpMethod.Post), cancellationToken);

            return(await HandleResponse <PayoutData>(response));
        }