So digging through the gem, looking at examples, and all that, I tried creating the following test:
#!/usr/bin/env ruby
require 'active_merchant'
require 'yaml'
require 'logger'
logger = Logger.new(STDOUT)
CONFIG = YAML.load(File.read(
File.expand_path("../paypal_api_signature.yml")
))
ActiveMerchant::Billing::Base.mode = :test
GATEWAY = ActiveMerchant::Billing::PaypalDigitalGoodsGateway.new(
:login => CONFIG['API_Username'],
:password => CONFIG['API_Password'],
:signature => CONFIG['Signature']
)
CC = YAML.load(File.read(
File.expand_path("../paypal_test_credit_card.yml")
))
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => CC['first_name'],
:last_name => CC["last_name"],
:number => CC["number"],
:month => CC["exp_month"],
:year => CC["exp_year"],
:verification_value => CC["cvv"]
)
if credit_card.valid?
amount = 200 # two dollah
options = {
:period => "Month",
:frequency => 1,
:start_date => Date.today,
:description => "Monthly Brewtoad Subscription"
}
logger.info "Calling GATEWAY.recurring to create recurring profile"
recurring_profile = GATEWAY.recurring(
amount,
credit_card,
options
)
if recurring_profile.success?
logger.info "Successfully charged %.2f to the credit card %s" % [ (amount.to_f / 100.0), credit_card.display_number ] else
logger.error "Charge failed: #{recurring_profile.message}"
end
else
logger.error "Invalid credit card"
end
which produces this output:
I, [2014-02-06T13:02:42.811436 #3332] INFO -- : Calling GATEWAY.recurring to create recurring profile
I, [2014-02-06T13:02:42.811506 #3332] INFO -- : Amount: 200
I, [2014-02-06T13:02:42.811547 #3332] INFO -- : Credit Card: #<ActiveMerchant::Billing::CreditCard:0x007fa9d3aa07d8 @first_name="Tamara", @last_name="Temple", @number="4928841618325417", @month=2, @year=2019, @verification_value="111", @errors={"number"=>[], "brand"=>[]}, @brand="visa">
I, [2014-02-06T13:02:42.811613 #3332] INFO -- : Options: {:period=>"Month", :frequency=>1, :start_date=>Thu, 06 Feb 2014, :description=>"Monthly Brewtoad Subscription"}
/Users/tamara/.gem/ruby/2.0.0/gems/activemerchant-1.42.4/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb:128:in `block (3 levels) in build_create_profile_request': undefined method `add_credit_card' for #<ActiveMerchant::Billing::PaypalDigitalGoodsGateway:0x007fa9d3aa3528> (NoMethodError)
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `call'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!'
from /Users/tamara/.gem/ruby/2.0.0/gems/activemerchant-1.42.4/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb:125:in `block (2 levels) in build_create_profile_request'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `call'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!'
from /Users/tamara/.gem/ruby/2.0.0/gems/activemerchant-1.42.4/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb:123:in `block in build_create_profile_request'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `call'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures'
from /Users/tamara/.gem/ruby/2.0.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!'
from /Users/tamara/.gem/ruby/2.0.0/gems/activemerchant-1.42.4/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb:122:in `build_create_profile_request'
from /Users/tamara/.gem/ruby/2.0.0/gems/activemerchant-1.42.4/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb:31:in `recurring'
from ./test.rb:46:in `<main>'
So what am I missing here? How do I tell Paypal to use the credit card the user enters for our monthly subscription digital good?
Paypal documents are useless here; I cannot make heads or tails of them to do what we need to do.