コード例 #1
0
        public async Task <MobilePayPaymentDetails> InitiatePayment(MobilePayPaymentRequest paymentRequest)
        {
            try
            {
                var response = await _paymentsApi.PaymentsPOSTAsync(null, new InitiatePaymentRequest
                {
                    Amount         = ConvertAmountToOrer(paymentRequest.Amount),
                    IdempotencyKey = paymentRequest.OrderId,
                    PaymentPointId = _mobilePaySettings.PaymentPointId,
                    RedirectUri    = "analogcoffeecard://mobilepay_purchase", // FIXME
                    Reference      = paymentRequest.OrderId.ToString(),
                    Description    = paymentRequest.Description
                });

                return(new MobilePayPaymentDetails(paymentRequest.OrderId.ToString(), response.MobilePayAppRedirectUri,
                                                   response.PaymentId.ToString(), null));
            }
            catch (ApiException <ErrorResponse> e)
            {
                var errorResponse = e.Result;
                Log.Error(
                    "MobilePay InitiatePayment failed with HTTP {StatusCode}. ErrorCode: {ErrorCode} Message: {Message} CorrelationId: {CorrelationId}",
                    e.StatusCode, errorResponse.Code, errorResponse.Message, errorResponse.CorrelationId);

                // FIXME Consider retry

                throw new MobilePayApiException(e.StatusCode, errorResponse.Message, errorResponse.Code);
            }
            catch (ApiException apiException)
            {
                LogMobilePayException(apiException);
                throw new MobilePayApiException(apiException.StatusCode, apiException.Message);
            }
        }