def purchase updating_card = current_user.account.present? options = { :IpAddress => request.ip, :AccountId => current_user.email, :Name => params[:name], :JsonData => { plan: params[:plan], updating_card: updating_card }.to_json, :Currency => current_subscription.currency, :Description => "Storing card details" } current_subscription.plan = Plan.find(params[:plan]) if params[:plan].present? amount = updating_card ? 1 : current_subscription.amount response = gateway.purchase(params[:cryptogram], amount, options, true) # making response as action controller params @params = parametrize(response.params) if response.success? resp = { json: success_transaction(@params) } else # if 3d-secure needed if @params and @params['PaReq'].present? resp = { json: { response: @params, type: '3ds' }, status: 422 } else resp = { json: { response: response, type: 'error' }, status: 422 } end end render resp end private def gateway ActiveMerchant::Billing::CloudpaymentsGateway.new(public_id: configatron.cloudpayments.public_id, api_secret: configatron.cloudpayments.api_secret) end
def post3ds response = gateway.check_3ds(params[:MD], params[:PaRes]) @params = parametrize(response.params) if response.success? resp = success_transaction(@params) else resp = { message: response.message } end @response = { response: resp, success: response.success? } end
javascript: var resp = JSON.parse('#{@response.to_json.html_safe}'); parent.window.showMessage(resp);
window.showMessage = function(r) { alert(r.response.message); }
Source: https://habr.com/ru/post/240573/
All Articles