Created
December 31, 2019 02:42
-
-
Save staycreativedesign/366964b45f3b295b5325d8c7a6c55d6d to your computer and use it in GitHub Desktop.
when successful it sends a rails ajax post to donations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DonationsController < ApplicationController | |
def new | |
end | |
def create | |
amount = CorrectMoneyService.new(params[:amount]).call | |
@current_user = FindMemberService.new(params).call | |
session[:user_id] = @current_user.id | |
#begin | |
AttachPaymentMethodService.new(@current_user.stripe_id, params[:cc]).call | |
#rescue Stripe::CardError => e | |
# binding.pry | |
# respond_to do |format| | |
# format.js { } | |
# end | |
# end | |
charge_type = CheckChargeType.new(@current_user.stripe_id, params, amount).call | |
@intent = case charge_type | |
when "custom_monthly" | |
when "monthly" | |
when "charge" | |
@intent = CreatePaymentIntentService.new(@current_user, amount, params ).call | |
end | |
if @intent[1].has_value?(true) | |
redirect_to thank_you_path | |
else | |
end | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started POST "/donations" for ::1 at 2019-12-30 21:41:40 -0500 | |
Processing by DonationsController#create as */* | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Zqa3djUGM64ylO1ph+cKpMFk6sSonMZ1vTaLecU9PorVVPTQS3KOkunsmGfr00ptyairFhswQu7JrpqAz6LQtA==", "name"=>"Gustavo Pares", "phone"=>"13056193724", "email"=>"gustavoanal | |
[email protected]", "address_line1"=>"3540 South Marion Ave", "address_city"=>"Tulsa", "address_state"=>"OK", "address_zip"=>"74135", "address_country"=>"United States", "dedication"=>"", "amount"=>"250.00", "cc"=> | |
"pm_1FvafwLe7Ukzj8Aa1UIanfMw", "subscription"=>"", "custom"=>"", "plan"=>"plan_Ew2RkoXy6PoFns", "charge_type"=>"donation"} | |
Membership Load (0.3ms) SELECT "memberships".* FROM "memberships" WHERE "memberships"."email" = $1 LIMIT $2 [["email", "[email protected]"], ["LIMIT", 1]] | |
CACHE Membership Load (0.0ms) SELECT "memberships".* FROM "memberships" WHERE "memberships"."email" = $1 LIMIT $2 [["email", "[email protected]"], ["LIMIT", 1]] | |
Redirected to http://localhost:3000/thank-you | |
Completed 200 OK in 2584ms (ActiveRecord: 0.3ms) | |
The redirection does not complete I have noticed that #create as */* is not the normal HTML |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stripe | |
.createPaymentMethod({ | |
type: 'card', | |
card: cardNumberElement, | |
billing_details: { | |
name: $('#name').val(), | |
}, | |
}) | |
.then(function(result) { | |
if(result.error) { | |
console.log(result.error) | |
} else { | |
console.log(result.paymentMethod.id) | |
console.log("winning") | |
$("#cc").val(result.paymentMethod.id) | |
var formData = new FormData(form) | |
console.log(formData.entries()) | |
Rails.ajax({ | |
url: "/donations", | |
type: "post", | |
data: formData, | |
success: function(data) { | |
}, | |
error: function(data) {} | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment