Esempio n. 1
0
        public async Task PostProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            HttpContext httpContext = processPaymentRequest.HttpContext;

            try
            {
                if (processPaymentRequest.PaymentStatus == PaymentStatus.Paid)
                {
                    return;
                }

                int selectedCurrencyId = processPaymentRequest.SelectedCurrencyId;
                PaystackSupportedCurrency supportedCurrency = await _supportedCurrencyService.GetSupportedCurrencyById(selectedCurrencyId);

                if (supportedCurrency == null || supportedCurrency.Id <= 0)
                {
                    throw new ArgumentNullException("Plugins.SmartStore.Paystack.SupportedCurrencyNullArgument");
                }

                PaystackSetting paystackSettings = await _settingService.GetSetting <PaystackSetting>();

                if (paystackSettings == null)
                {
                    throw new ArgumentNullException("Plugins.SmartStore.Paystack.PaystackSettingsNullArgument");
                }

                PaystackTransaction transactionResponse = await _gatewayLuncher.MakePayment(processPaymentRequest, paystackSettings, supportedCurrency, httpContext);

                if (transactionResponse != null && transactionResponse.status && !string.IsNullOrWhiteSpace(transactionResponse.Data.authorization_url))
                {
                    await _gatewayLuncher.LogTransaction(transactionResponse);

                    await _gatewayLuncher.LunchPaymentPage(httpContext, transactionResponse.Data.authorization_url);
                }
                else
                {
                    string errorMessage = transactionResponse != null ? transactionResponse.message : string.Format("Plugins.SmartStore.Paystack.EmptyGatewayResponseMessage");
                    httpContext.Session.SetString(_gatewayLuncher.ErrorMessage, errorMessage);
                }
            }
            catch (Exception ex)
            {
                httpContext.Session.SetString(_gatewayLuncher.ErrorMessage, ex.Message);
            }
        }