class PagSeguro::Subscription
It lets you create a subscription without going through PagSeguro
screens.
Constants
- API_VERSION
- TEN_DAYS_IN_SECONDS
Attributes
charge[RW]
Set the charge
code[RW]
The code of a created to the subscription, must be saved
date[RW]
Set the date
last_event_date[RW]
Set the last event date
name[RW]
Set the name
payment_method[R]
Get the payment method
plan[RW]
Set the plan
reference[RW]
Set the reference
sender[R]
Get the sender
status[RW]
Set the status
tracker[RW]
Set the tracker
Public Class Methods
find_by_code(code, options={})
click to toggle source
Find subscription by subscription code
# File lib/pagseguro/subscription.rb, line 74 def self.find_by_code(code, options={}) load_from_response send_request("pre-approvals/#{code}", options[:credentials]) end
find_by_notification_code(code, options={})
click to toggle source
Find subscription by notification code
# File lib/pagseguro/subscription.rb, line 69 def self.find_by_notification_code(code, options={}) load_from_response send_request("pre-approvals/notifications/#{code}", options[:credentials]) end
load_from_xml(xml)
click to toggle source
# File lib/pagseguro/subscription.rb, line 101 def self.load_from_xml(xml) new ResponseSerializer.new(xml).serialize_from_search end
search_by_date_interval(options={})
click to toggle source
# File lib/pagseguro/subscription.rb, line 89 def self.search_by_date_interval(options={}) # Default options options = { starts_at: Time.now, ends_at: Time.now - TEN_DAYS_IN_SECONDS, per_page: 50, page: 0 }.merge(options) SubscriptionSearch.new('pre-approvals', options) end
search_by_days_interval(options={})
click to toggle source
# File lib/pagseguro/subscription.rb, line 78 def self.search_by_days_interval(options={}) # Default options options = { interval: 30, per_page: 50, page: 0 }.merge(options) SubscriptionSearch.new('pre-approvals/notifications', options) end
Private Class Methods
send_request(path, credentials)
click to toggle source
Send a get request to API version, with the path given
# File lib/pagseguro/subscription.rb, line 116 def self.send_request(path, credentials) Request.get_with_auth_on_url(path, API_VERSION, credentials) end
Public Instance Methods
create()
click to toggle source
# File lib/pagseguro/subscription.rb, line 58 def create request = Request.post_xml('pre-approvals', nil, credentials, xml_params, extra_options) Response.new(request, self).serialize self end
errors()
click to toggle source
# File lib/pagseguro/subscription.rb, line 64 def errors @errors ||= Errors.new end
payment_method=(payment_method)
click to toggle source
Set the payment method
# File lib/pagseguro/subscription.rb, line 50 def payment_method=(payment_method) @payment_method = ensure_type(SubscriptionPaymentMethod, payment_method) end
sender=(sender)
click to toggle source
Set the sender
# File lib/pagseguro/subscription.rb, line 45 def sender=(sender) @sender = ensure_type(Sender, sender) end
update_attributes(attrs)
click to toggle source
# File lib/pagseguro/subscription.rb, line 54 def update_attributes(attrs) attrs.each {|name, value| send("#{name}=", value) } end
Private Instance Methods
after_initialize()
click to toggle source
# File lib/pagseguro/subscription.rb, line 128 def after_initialize @errors = Errors.new end
extra_options()
click to toggle source
# File lib/pagseguro/subscription.rb, line 124 def extra_options { headers: { "Accept" => "application/vnd.pagseguro.com.br.v1+xml;charset=ISO-8859-1" }} end
xml_params()
click to toggle source
# File lib/pagseguro/subscription.rb, line 120 def xml_params RequestSerializer.new(self).serialize end