public virtual async Task <RefundResult> RefundAsync(string merchantRefundId, string paymentId, int amount, string reason, string nonce, string currency = "JPY")
        {
            DateTimeOffset timestamp = DateTimeOffset.UtcNow;
            long           epoc      = timestamp.ToUnixTimeSeconds();

            RefundRequestModel requestOpject = new RefundRequestModel
            {
                MerchantRefundId = merchantRefundId,
                Amount           = new PayPayAmount
                {
                    Amount   = amount,
                    Currency = currency,
                },
                PaymentId   = paymentId,
                RequestedAt = epoc,
                Reason      = reason,
            };

            string        json        = JsonConvert.SerializeObject(requestOpject);
            StringContent content     = new StringContent(json, Encoding.UTF8, "application/json");
            string        contentType = content.Headers.GetValues("Content-Type").First();
            string        path        = "/v2/refunds";
            string        method      = "POST";

            var headerAuthorizationObject = this.GetHeaderAuthorizationObject(json, contentType, path, method, nonce, epoc);
            var authorization             = new AuthenticationHeaderValue("hmac", headerAuthorizationObject);

            var result = await SendAsync(HttpMethod.Post, $"{this.Uri}{path}", authorization, content, this.MerchantId);

            var responseContent = await result.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <RefundResult>(responseContent);

            return(response);
        }
Ejemplo n.º 2
0
        public RefundRequestModel Details(int refundRequestId)
        {
            if (refundRequestId <= 0)
            {
                throw new CustomException(400, "Id de reembolso inválido");
            }

            var refundRequest = _unitOfWork.RefundRequest.GetById(refundRequestId);

            if (refundRequest == null)
            {
                throw new CustomException(404, "No se pudo encontrar el reembolso");
            }

            // Maps the refund request db entity to view model entity
            RefundRequestModel refundRequestModel = _mapper.Map <RefundRequestModel>(refundRequest);

            return(refundRequestModel);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> RefundAsync([FromBody] RefundRequestModel request)
        {
            try
            {
                RefundResult refundResult = await _refundService.ExecuteAsync(request.MerchantId,
                                                                              request.PaymentRequestId, request.DestinationAddress);

                return(Ok(Mapper.Map <RefundResponseModel>(refundResult)));
            }
            catch (RefundOperationFailedException e)
            {
                _log.ErrorWithDetails(e, new { errors = e.TransferErrors });
            }
            catch (AssetUnknownException e)
            {
                _log.ErrorWithDetails(e, new { e.Asset });
            }
            catch (AssetNetworkNotDefinedException e)
            {
                _log.ErrorWithDetails(e, new { e.AssetId });
            }
            catch (Exception e)
            {
                _log.ErrorWithDetails(e, request);

                if (e is RefundValidationException validationEx)
                {
                    _log.ErrorWithDetails(e, new { validationEx.ErrorType });

                    return(BadRequest(new RefundErrorModel {
                        Code = validationEx.ErrorType
                    }));
                }
            }

            return(BadRequest(new RefundErrorModel {
                Code = RefundErrorType.Unknown
            }));
        }
        public async Task <ActionResult> RefundMoney(RefundMoneyDialogViewModel vm)
        {
            try
            {
                if (string.IsNullOrEmpty(vm.SelectedWallet))
                {
                    return(this.JsonFailResult("Error: needs to select source wallet", ErrorMessageAnchor));
                }
                var refund = new RefundRequestModel()
                {
                    DestinationAddress = vm.ManualWalletAddress ?? vm.SelectedWallet,
                    PaymentRequestId   = vm.SelectedPaymentRequest,
                    MerchantId         = vm.SelectedMerchant
                };
                var response = await _payInternalClient.RefundAsync(refund);

                return(this.JsonRequestResult("#transfersList", Url.Action("TransfersList"), new TransfersPageViewModel()
                {
                    SelectedMerchant = vm.SelectedMerchant, SelectedAsset = "None"
                }));
            }
            catch (RefundErrorResponseException ex)
            {
                if (ex.InnerException != null)
                {
                    var content = JsonConvert.DeserializeObject <PayInternalException>(((Refit.ApiException)ex.InnerException).Content);
                    if (content.Code == Helpers.RefundErrorType.Unknown)
                    {
                        return(this.JsonFailResult("Error code: Internal Error", ErrorMessageAnchor));
                    }
                    return(this.JsonFailResult("Error code: " + content.Code, ErrorMessageAnchor));
                }
                else
                {
                    return(this.JsonFailResult(ex.Message, ErrorMessageAnchor));
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> RefundAsync([FromBody] RefundRequestModel request)
        {
            try
            {
                RefundResult refundResult = await _refundService.ExecuteAsync(request.MerchantId,
                                                                              request.PaymentRequestId, request.DestinationAddress);

                return(Ok(Mapper.Map <RefundResponseModel>(refundResult)));
            }
            catch (RefundOperationFailedException refundFailedEx)
            {
                await _log.WriteErrorAsync(nameof(RefundAsync), new { errors = refundFailedEx.TransferErrors }.ToJson(), refundFailedEx);
            }
            catch (AssetUnknownException assetEx)
            {
                await _log.WriteErrorAsync(nameof(RefundAsync), new { assetEx.Asset }.ToJson(), assetEx);
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(RefundAsync), request.ToJson(), ex);

                if (ex is RefundValidationException validationEx)
                {
                    await _log.WriteErrorAsync(nameof(RefundAsync),
                                               new { errorType = validationEx.ErrorType.ToString() }.ToJson(), validationEx);

                    return(BadRequest(new RefundErrorModel {
                        Code = validationEx.ErrorType
                    }));
                }
            }

            return(BadRequest(new RefundErrorModel {
                Code = RefundErrorType.Unknown
            }));
        }
Ejemplo n.º 6
0
 public Task <RefundResponseModel> Authorize(RefundRequestModel request)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
 public Task <RefundResponse> RefundAsync(RefundRequestModel request)
 {
     return(_runner.RunAsync(() => _paymentRequestsApi.RefundAsync(request), ExceptionFactories.CreateRefundException));
 }
Ejemplo n.º 8
0
 public async Task <RefundResponseModel> RefundAsync(RefundRequestModel innerRequest)
 {
     innerRequest.SiteReference = _config.SiteReference;
     return(await RequestAsync <RefundRequestModel, RefundResponseModel>(innerRequest));
 }