#ruby #ruby-on-rails-5 #stripe-payments
#ruby #ruby-on-rails-5 #stripe-платежи
Вопрос:
Привет всем, ребята, у меня проблема с транзакцией на stripe. В принципе, я зарегистрировался на сайте и таким образом правильно настроил как файл .env со значением ключей, так и файл stripe.rb:
это stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['INCIBUS_STRIPE_PUBLISH_KEY'],
:secret_key => ENV['INCIBUS_STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
это файл .env:
INCIBUS_STRIPE_PUBLISH_KEY=xxxxxxxxxxxxxxxxxxxxx
INCIBUS_SSTRIPE_SECRET_KEY=xxxxxxxxxxxxxxxxxxxx
Когда я заполняю форму, в которую я ввожу данные для карты,
заставляет меня нажать кнопку «Оплатить», и когда она загружается, у меня возникает ошибка в контроллере
это контроллер: выдает мне ошибку в методе stripe_payament:
class Suppliers::Dashboard::CurrentSubscriptionController < Suppliers::DashboardController
skip_before_action :verify_supplier_subscriptions_payment
skip_before_action :verify_authenticity_token, only: [:stripe_payment, :paypal_payment, :execute_paypal_payment]
skip_before_action :verify_subscription_expire_date
before_action :verify_subscription_allowance, only: [:set]
def show
@subscription = subscription
@subscription_types = SupplierSubscriptionType.for_customers.select { |i| i.price >= subscription.type.price }
end
def set
session[:current_subscription] = params[:id].to_i
redirect_to suppliers_dashboard_path
end
def stripe_payment
subscription = current_user.supplier_subscription
customer = Stripe::Customer.create(
email: params[:stripeEmail],
source: params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => (subscription.last_invoice.amount*100).to_i,
:description => subscription.last_invoice.number,
:currency => 'eur'
)
if charge.paid
subscription.update(expire_date: subscription.created_at subscription.type.duration.days)
subscription.last_invoice.update(is_payed: true, payed_at: Time.now)
redirect_to suppliers_dashboard_subscription_path, notice: "Pagamento effettuato con successo"
else
render :back, error: "Errore del pagamento"
end
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to :back
end
def paypal_payment
subscription = current_user.supplier_subscription
@payment = PayPal::SDK::REST::Payment.new(
{
intent: "sale",
payer: { payment_method: "paypal" },
redirect_urls: {
return_url: "#{request.protocol}#{request.host}#{ Rails.env.development? ? ":3000" : "" }/produttori/dashboard/current_subscription/execute_paypal_payment",
cancel_url: "#{request.protocol}#{request.host}#{ Rails.env.development? ? ":3000" : "" }/produttori/dashboard/current_subscription"
# return_url: "https://www.incibus.com/produttori/dashboard/current_subscription/execute_paypal_payment",
# cancel_url: "https://www.incibus.com/produttori/dashboard/current_subscription"
},
transactions: [{
amount: {
total: subscription.last_invoice.amount,
currency: "EUR"
},
description: "creating a payment"
}]
}
)
if @payment.create
redirect_to @payment.approval_url
end
end
def execute_paypal_payment
subscription = current_user.supplier_subscription
@payment = PayPal::SDK::REST::Payment.find(params["paymentId"])
if @payment.execute( payer_id: params["PayerID"] )
subscription.update(expire_date: subscription.created_at subscription.type.duration.days)
subscription.last_invoice.update(is_payed: true, payed_at: Time.now)
redirect_to suppliers_dashboard_subscription_path, notice: "Pagamento effettuato con successo"
end
end
# def bank_transfer
# @subscription = current_user.innkeeper_subscription
# end
# def bank_transfer_payment
# subscription = current_user.innkeeper_subscription
# subscription.last_invoice.update(iban: params[:innkeeper_subscription][:iban])
# redirect_to dashboard_subscription_path, notice: "Invio coordinate bancarie effettuato"
# end
private
def verify_subscription_allowance
unless current_user.available_supplier_subscriptions.map(amp;:id).include?(params[:id].to_i)
redirect_to suppliers_dashboard_path
end
end
end
это трассировка стека:
Stripe::AuthenticationError - No API key provided. Set your API key using "Stripe.api_key = <API-KEY>". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.:
stripe (1.58.0) lib/stripe.rb:159:in `request'
stripe (1.58.0) lib/stripe/api_operations/request.rb:15:in `request'
stripe (1.58.0) lib/stripe/api_operations/create.rb:5:in `create'
app/controllers/suppliers/dashboard/current_subscription_controller.rb:20:in `stripe_payment'
actionpack (5.0.7.2) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.7.2) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.7.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.7.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:448:in `block (2 levels) in around'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:286:in `block (2 levels) in halting'
() var/lib/gems/2.5.0/bundler/gems/route_translator-9d3350d9574c/lib/route_translator/extensions/action_controller.rb:27:in `set_locale_from_url'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:382:in `block in make_lambda'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:285:in `block in halting'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:447:in `block in around'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.7.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.7.2) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.7.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.7.2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.7.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.7.2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.7.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.7.2) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
searchkick (2.3.0) lib/searchkick/logging.rb:209:in `process_action'
activerecord (5.0.7.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.7.2) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.7.2) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.7.2) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.7.2) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.7.2) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.7.2) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.7.2) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.7.2) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.7.2) lib/action_dispatch/routing/route_set.rb:727:in `call'
omniauth (1.4.1) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.4.1) lib/omniauth/strategy.rb:164:in `call'
bullet (5.5.0) lib/bullet/rack.rb:12:in `call'
warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
warden (1.2.9) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.7.2) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.7.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.7.2) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
() var/lib/gems/2.5.0/bundler/gems/better_errors-707ffcf284d8/lib/better_errors/middleware.rb:84:in `protected_app_call'
() var/lib/gems/2.5.0/bundler/gems/better_errors-707ffcf284d8/lib/better_errors/middleware.rb:79:in `better_errors_call'
() var/lib/gems/2.5.0/bundler/gems/better_errors-707ffcf284d8/lib/better_errors/middleware.rb:57:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.7.2) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.7.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.7.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.7.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.7.2) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.7.2) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
request_store (1.3.2) lib/request_store/middleware.rb:9:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.7.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
rack-livereload (0.3.16) lib/rack/livereload.rb:23:in `_call'
rack-livereload (0.3.16) lib/rack/livereload.rb:14:in `call'
actionpack (5.0.7.2) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
rack-cors (0.4.1) lib/rack/cors.rb:81:in `call'
railties (5.0.7.2) lib/rails/engine.rb:522:in `call'
puma (3.7.0) lib/puma/configuration.rb:226:in `call'
puma (3.7.0) lib/puma/server.rb:578:in `handle_request'
puma (3.7.0) lib/puma/server.rb:415:in `process_client'
puma (3.7.0) lib/puma/server.rb:275:in `block in run'
puma (3.7.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Комментарии:
1. Чтобы определить проблему, не могли бы вы попробовать использовать статические учетные данные во
stripe.rb
что-то вроде этогоStripe.api_key =xxxxxxxxxxxxxxxxxxxxx
2. пытаясь это сделать, я получаю сообщение об ошибке «Ошибка ключа — ключ не найден : : шифры:»
3. Если возможно, пожалуйста, обновите свой вопрос с последней ошибкой отслеживания стека.