Braintree Error In Production Mode - ruby-on-rails
I have implemented Braintree subscription payment in rails app. Everything works fine in development, however when I switched to production (I have registered with Braintree and got a real account, and I change all the key in environment)
I have tried to submit an invalid card information to test the app, the page keeps showing error.
I look at the application logs and it said
NoMethodError (undefined method `customer' for #<Braintree::ErrorResult:0x007f6ed80f1d80>):
Here's my create method, I follow your tutorial and it works fine in development
def create
if current_user.braintree_id?
customer = Braintree::Customer.find(current_user.braintree_id)
else
result = Braintree::Customer.create(
email: current_user.company_email,
company: current_user.company_name,
payment_method_nonce: params[:payment_method_nonce]
)
customer = result.customer
current_user.update(braintree_id: customer.id)
end
result = Braintree::Subscription.create(
payment_method_token: customer.payment_methods.find{ |pm| pm.default? }.token,
plan_id: params[:plan_id]
)
if result.success?
result.subscription.transactions.each do |transaction|
current_user.transactions.create(braintree_transaction_id: transaction.id,
plan_name: params[:plan_name],
price: transaction.amount.to_f,
start_date: transaction.subscription_details.billing_period_start_date,
end_date: transaction.subscription_details.billing_period_end_date,
subscription_id: result.subscription.id
)
end
current_user.update(braintree_subscription_id: result.subscription.id,
next_billing_date: result.subscription.next_billing_date,
billing_period_start_date: result.subscription.billing_period_start_date,
billing_period_end_date: result.subscription.billing_period_end_date,
status: result.subscription.status,
next_billing_period_amount: result.subscription.next_billing_period_amount,
paid_through_date: result.subscription.paid_through_date,
plan_id: params[:plan_id],
plan_name: params[:plan_name])
flash[:info] = "You've been subscribed successfully"
redirect_to #current_user
else
flash[:warning] = "Invalid card information"
render 'new'
end
end
The weird thing is it doesn't render the flash warning of unsuccessful result and redirect to the original new_subscription_path, instead the website url redirect to this
https://herokuappname.herokuapp.com/subscription.1
and the page error shows
This page isn’t working herokuappname.herokuapp.com is currently unable to handle this request.
HTTP ERROR 500
So, I want to know whether it is the customer method error (which I don't think so because it doesn't have any problem in development mode) or any other problem such as why the page url so weird?
I looked at the Braintree control panel, and the reason that the subscription failed was because the bank declined the transactions due to incorrect card information, which I entered incorrect card in order to test it, if it is invalid card info, why didn't it display the flash notice and redirect back to the new_subscription_path, instead it redirects to the subscription.1 url which I have mentioned above?
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
I'm not sure if you used the same invalid card number for testing in production as in sandbox, but I'll try to answer your questions with the information we have on hand:
NoMethodError (undefined method `customer' for #):
By attempting to create a customer with a payment method with an invalid card, the result of that API call was an ErrorResult object. ErrorResult objects are either a validation error, processor decline, gateway rejection, or other exception messages, and do not contain a customer method. Hence, the undefined method error.
You should add some error handling around all of your Braintree API calls so that you can address any errors throughout the subscription process.
Related
ActiveMerchant Cybersource Authorization Error Reason 102
I'm work on debugging an application that is currently running on Ruby 2.5.8 with ActiveMerchant 1.117.0. I am able to create and save the subscription successfully. However, when I try to authorize the saved card I keep getting reasonCode 102. The error from the Cybersource gateway side is the subscription () could not be found. I'm attempting to authorize with the function: def authorize(token, amount, order_id, line_items) response = gateway.authorize(amount, token, order_id: order_id, line_items: line_items) if !response.success? raise Exceptions::ChargeFailed.new(response.message, response: response) end response end The error would lead me to believe that the formatting here is not correct. Can anyone point me to some working ActiveMerchant CyberSource examples for authorizing a subscription or point out what might be wrong here?
After some digging, it appears that the logic for token assignment changed inside of the ActiveMerchant CyberSource gem The original logic was: if reference _, subscription_id, _ = reference.split(";") xml.tag! 'subscriptionID', subscription_id end The latest versions this shifted towards: if reference subscription_id = reference.split(";")[6] xml.tag! 'subscriptionID', subscription_id end The application that I am working with previously had been formatting the CyberSource profile / subscription id as ;#{token};. In order to work with these latest updates the token needs to be formatted as ;;;;;;#{token}.
shopify application charge failing to save
Below is my code for a Shopify one-time-application-charge in Ruby. I followed the shopify "add billing to your app" page (https://help.shopify.com/api/tutorials/adding-billing-to-your-app) for the code, except didn't need a recurring charge. I have also found someone else who posted their one-time-charge code which looks very similar to mine (https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/one-time-application-charge-example-for-shopify-rails-app-489347). def create_application_charge application_charge = ShopifyAPI::ApplicationCharge.new( name: "MyApp", price: 0.09, return_url: "https:\/\/myapp.herokuapp.com\/activatecharge", test: true) save = application_charge.save if save redirect application_charge.confirmation_url return end flash[:error] = "The save worked: #{save}" end The flash always responds as false. Is there a failure at authentication that would prevent this? Or something to get the store to accept an application charge? I'm at a loss as to why this does not work. Any help would be greatly appreciated, thank you.
The primary issue appears to be that the minimum charge you can request is $0.50, for which I wasn't meeting with my choice of using $0.09 for my test.
stripe_event 404 error for test data, figuring out how to add stripe-account-header
I'm using stripe to verify a profile before any transactions happen, so I want to see webhooks that have type account.updated and check the verification.status. Im receiving a 404 error '(Status 404) (Request req_AwRiJSFxaOn1Jq) No such event: evt_1AaW9jFzjmmh0zTvsNSlfDLv I realize that i need a stripe account header for the specific account that the webhook is being made for. I cant figure out how to add an account header to my stripe.rb code. I saved the stripe_account_id in the database on account creation so i can pull that id out from the database. The part that confuses me is when the webhook sends to my app the account_id is in the webhook, so it seems I have to pull that part out of the webhook and paste into stripe.rb {:stripe_account => CONNECTED_STRIPE_ACCOUNT_ID}. how is this possible? This is the webhook that was sent from stripe in console (this is test data so i dont mind that people can see this cause its getting deleted soon anyways) stripe.rb require 'stripe' Rails.configuration.stripe = { :publishable_key => ENV["STRIPE_PUBLISHABLE_KEY"], :secret_key => ENV["STRIPE_SECRET_KEY"] } Stripe.api_key = ENV["STRIPE_SECRET_KEY"] StripeEvent.configure do |events| events.all do |event| # target specific events here puts "this is working so far" if event.type == 'account.updated' account_event = event.data.object puts "account updated working" puts "#{account_event}" end end end I received the webhook in stripe connected account dashboard and my app console.
You're likely missing the Stripe-Account header, so it's trying to fetch the Event from your Account, rather than from the Stripe Account in which it exists. EDIT: Sorry, I totally misunderstood your question. I think you need to configure the StripeEvent receiver to use the Stripe Account.
Gibbon API does not error, but does not subscribe
This is a strange one. I've had a working MailChimp, Gibbon, RoR app going for a couple of years now, and I went to go use part of my app this week and realized that the integration was no longer working. I am not receiving any errors, and some basic testing shows that the exception section of the code is never called. Here is the code I am using: begin gb = Gibbon::API.new(mailchimp_api_key) gb.lists.subscribe( id: mailchimp_list_id, email: {email: email} ) rescue Gibbon::MailChimpError => e logger.error "Mailchimp threw an error. The code is: #{e.code}, with message: #{e.message}" end Some code edited for readability, but assume that the variables are defined and no errors are thrown. What I'm looking for is some debugging help. I can't seem to find a way to debug the integration to know if there is something silently failing or not. Does anyone have any tips for debugging this outside of trying to catch a raised exception?
I use the same code and when something wrong an exception is thrown. You should check and print what subscribeis returning. response = gb.lists.subscribe( id: mailchimp_list_id, email: {email: email} ) puts response According to the mailchimp documentation it should return a JSON like this one : { "email": "example email", "euid": "example euid", "leid": "example leid" } https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
Thanks! And yep, I do get a response back that matches what you suggested (note, I used a real email address): { "email"=>"my#email.com", "euid"=>"3cb513752a", "leid"=>"89681797" } Strangely enough, it does show up on the mailchimp side as pending subscription, but the subscription confirmation is not sending. That sounds like I have a MailChimp problem, not a gibbon problem. Does anyone know of a setting on the MailChimp side I am missing? Will keep digging...
Getting error 87 at payment Authorize.net in Rails 3
I have created a test account with Authorize.net. My development environment is rails 3 and I am trying to implement the Server Integration Method (SIM) by using static IP. But I am getting an error: "3,1,87,(TESTMODE) Transactions of this market type cannot be processed on this system.,000000,P,0,,,199.00,,auth_capture,,,,,,,,,,,,,,,,,,,,,,,,,,D3EA25CA1DF97765286A48C6B22287F4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,✓,uSIUUgX0d++dIheYjcHdlztlViD/r4YDUP9rEuEy9U8=,Purchase" when send request to "AuthorizeNet::SIM::Transaction::Gateway::TEST" gateway. I also found this link: others got similar type error But not helpful. Any suggestions how to resolve this error? I wrote following codes in the action. #amount = 10.00 #sim_transaction = AuthorizeNet::SIM::Transaction.new('API Login ID', 'Transaction Key', #amount, :hosted_payment_form => true) #sim_transaction.set_hosted_payment_receipt(AuthorizeNet::SIM::HostedReceiptPage.new(:link_method => AuthorizeNet::SIM::HostedReceiptPage::LinkMethod::GET, :link_text => 'Continue', :link_url => payments_thank_you_url(:only_path => false)))
Since you are dealing with credit card transactions through web applications, you need to make sure your Sandbox account is of "Card Not Present" type. If you don't remember which type you set it to, it is a good idea to create a new account and make sure to select "Card Not Present" option. Otherwise, you will get this error message. I hope this helps.