Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/paypal/recurring/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module PayPal
module Recurring
class Base
attr_accessor :amount
attr_accessor :billing_type
attr_accessor :cancel_url
attr_accessor :currency
attr_accessor :description
Expand All @@ -20,6 +21,7 @@ class Base
attr_accessor :reference
attr_accessor :refund_type
attr_accessor :return_url
attr_accessor :solution_type
attr_accessor :start_at
attr_accessor :token
attr_accessor :transaction_id
Expand Down Expand Up @@ -68,11 +70,12 @@ def checkout
:item_category,
:item_name,
:item_amount,
:item_quantity
:item_quantity,
:solution_type,
:billing_type
).merge(
:payment_action => "Authorization",
:no_shipping => 1,
:L_BILLINGTYPE0 => "RecurringPayments"
)

request.run(:checkout, params)
Expand Down
33 changes: 27 additions & 6 deletions lib/paypal/recurring/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class Request

PERIOD = {
:daily => "Day",
:weekly => "Weekly",
:weekly => "Week",
:monthly => "Month",
:yearly => "Year"
}

TRIAL_PERIOD = {
:daily => "Day",
:weekly => "Weekly",
:weekly => "Week",
:monthly => "Month",
:yearly => "Year"
}
Expand All @@ -49,6 +49,17 @@ class Request
:other => "Other"
}

SOLUTION_TYPES = {
:sole => "Sole",
:mark => "Mark"
}

BILLING_TYPES = {
:merchant => "MerchantInitiatedBilling",
:recurring => "RecurringPayments",
:single => "MerchantInitiatedBillingSingleAgreement"
}

ATTRIBUTES = {
:action => "ACTION",
:amount => ["PAYMENTREQUEST_0_AMT", "AMT"],
Expand Down Expand Up @@ -82,6 +93,7 @@ class Request
:signature => "SIGNATURE",
:start_at => "PROFILESTARTDATE",
:token => "TOKEN",
:solution_type => "SOLUTIONTYPE",
:transaction_id => "TRANSACTIONID",
:trial_amount => "TRIALAMT",
:trial_frequency => "TRIALBILLINGFREQUENCY",
Expand Down Expand Up @@ -153,10 +165,11 @@ def client

def default_params
{
:username => PayPal::Recurring.username,
:password => PayPal::Recurring.password,
:signature => PayPal::Recurring.signature,
:version => PayPal::Recurring.api_version
:billing_type => :recurring,
:username => PayPal::Recurring.username,
:password => PayPal::Recurring.password,
:signature => PayPal::Recurring.signature,
:version => PayPal::Recurring.api_version
}
end

Expand Down Expand Up @@ -197,6 +210,14 @@ def build_action(value) # :nodoc:
ACTIONS.fetch(value.to_sym, value) if value
end

def build_solution_type(value) # :nodoc:
SOLUTION_TYPES.fetch(value.to_sym, value) if value
end

def build_billing_type(value) # :nodoc:
BILLING_TYPES.fetch(value.to_sym, value) if value
end

def build_initial_amount_action(value) # :nodoc:
INITIAL_AMOUNT_ACTIONS.fetch(value.to_sym, value) if value
end
Expand Down
8 changes: 4 additions & 4 deletions lib/paypal/recurring/response/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class Profile < Base
}

PERIOD = {
"Month" => :monthly,
"Weekly" => :weekly,
"Year" => :yearly,
"Day" => :daily
"Month" => :monthly,
"Week" => :weekly,
"Year" => :yearly,
"Day" => :daily
}

def active?
Expand Down
4 changes: 2 additions & 2 deletions spec/paypal/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@

it "normalizes period" do
subject.normalize_params(:period => :monthly).should == {:BILLINGPERIOD => "Month"}
subject.normalize_params(:period => :weekly).should == {:BILLINGPERIOD => "Weekly"}
subject.normalize_params(:period => :weekly).should == {:BILLINGPERIOD => "Week"}
subject.normalize_params(:period => :daily).should == {:BILLINGPERIOD => "Day"}
subject.normalize_params(:period => :yearly).should == {:BILLINGPERIOD => "Year"}
end

it "normalizes trial period" do
subject.normalize_params(:trial_period => :monthly).should == {:TRIALBILLINGPERIOD => "Month"}
subject.normalize_params(:trial_period => :weekly).should == {:TRIALBILLINGPERIOD => "Weekly"}
subject.normalize_params(:trial_period => :weekly).should == {:TRIALBILLINGPERIOD => "Week"}
subject.normalize_params(:trial_period => :daily).should == {:TRIALBILLINGPERIOD => "Day"}
subject.normalize_params(:trial_period => :yearly).should == {:TRIALBILLINGPERIOD => "Year"}
end
Expand Down