Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:27:49+00:00 2026-06-13T06:27:49+00:00

I’m building an application that handles different types of transactions for different services such

  • 0

I’m building an application that handles different types of transactions for different services such as subscriptions, gift subscriptions and purchases.

I have an issue with the gift transactions and activemerchant. Ill give you a brief overview of how it works.

The user creates a gift subscription and fills out the data for it, it is stored in the db and then shown back to the user for review in a custom “show_view”, the user then proceeds to enter credit card information in a separate form and when he submits the data, a method from the controller is called to handle the transaction and here is where Im having issues.

This is the gift_subscription.rb model

    def gift_purchase
    response = GATEWAY.purchase(price, credit_card, gift_purchase_options)
    GiftTransaction.create!(:action => "gift_purchase", :amount => price, :response => response)
    response.success?
  end
  private
  def gift_purchase_options
    {
        :ip => ip_address,
        :billing_address => {
            :name     => name + last_name,
            :address1 => address1,
            :city     => city,
            :state    => state,
            :country  => "Mexico",
            :zip      => zip
        }
    }
  end

  def validate_card
    unless credit_card.valid?
      credit_card.errors.full_messages.each do |message|
        errors[:base] << message
      end
    end
  end

  def credit_card
    @credit_card = ActiveMerchant::Billing::CreditCard.new(
        :brand              => card_type,
        :number             => card_number,
        :verification_value => card_verification,
        :month              => card_expires_on.month,
        :year               => card_expires_on.year,
        :first_name         => name,
        :last_name          => last_name
    )

And here is the gift_subscription_controller.rb

def review
    @gift_subscription = GiftSubscription.find(params[:id])
  end

  def edit_review
    @gift_subscription = GiftSubscription.find(params[:id])
  end

  def update_review
  @gift_subscription = GiftSubscription.find(params[:id])

    respond_to do |format|
      if @gift_subscription.update_attributes(params[:gift_subscription])
        format.html { redirect_to "gift_subscriptions/review/#{@gift_subscription.id}", :notice => 'Gift subscription was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render :action => "edit_review" }
        format.json { render :json => @gift_subscription.errors, :status => :unprocessable_entity }
      end
    end
  end

  def do_gift_transaction
    @gift_subscription = GiftSubscription.find(params[:id])
    if @gift_subscription.gift_purchase
        redirect_to '/thank_you'
    else
        redirect_to "/gift_subscriptions/#{@gift_subscription.id}/failed_transaction"
    end
  end

  def failed_transaction
    @gift_subscription = GiftSubscription.find(params[:id])
    @gift_transactions = @gift_subscription.gift_transactions
  end

  def transaction_details
    @gift_subscription = GiftSubscription.find(params[:id])
  end

To make things a little more clear, from the controller create method, it redirects users to the review action where there’s an edit_review in case they want to change something, then they go to transaction_details where they enter creditcard info and finally the method do_gift_transaction is called to actually do the transaction.

The error I get is the following

NoMethodError in GiftSubscriptionsController#do_gift_transaction

undefined method `month' for nil:NilClass
Rails.root: /home/peanut/RubymineProjects/GiftBox

Application Trace | Framework Trace | Full Trace
app/models/gift_subscription.rb:44:in `credit_card'
app/models/gift_subscription.rb:12:in `gift_purchase'
app/controllers/gift_subscriptions_controller.rb:113:in `do_gift_transaction'

I’ve been looking around and I can’t seem to find why it doesnt recognize the month… For other subscriptions I have basically the same model (a few diferences) but it works perfectly. Any help here would be much appreciated.

GiftSubscription model attributes

attr_accessible :response, :name, :last_name, :address1, :address2,:city,
                  :state, :zip, :card_type, :ip_address, :price,
                  :duration, :created_at, :card_expires_on, :card_number,
                  :card_verification, :message

  has_one :gift_transactions, :class_name => "GiftTransaction"
  attr_accessor :card_number, :card_verification
  validate :validate_card, :on => :transaction_details
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:27:51+00:00Added an answer on June 13, 2026 at 6:27 am

    So after a few hours of banging my head it turned out to be quite simple… In the view to enter credit card data, the fields that were supposed to be saved to the db were not being saved because I only had a link_to button to continue and ergo when the credit_card method was called, it was empty.

    Thanks to lander16 for pointing this out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.