Class: PagSeguro::Subscription

Inherits:
Object
  • Object
show all
Includes:
Extensions::Credentiable, Extensions::EnsureType, Extensions::MassAssignment
Defined in:
lib/pagseguro/subscription.rb,
lib/pagseguro/subscription/response.rb,
lib/pagseguro/subscription/request_serializer.rb,
lib/pagseguro/subscription/response_serializer.rb

Overview

It lets you create a subscription without going through PagSeguro screens.

Defined Under Namespace

Classes: RequestSerializer, Response, ResponseSerializer

Constant Summary collapse

API_VERSION =
:v2
TEN_DAYS_IN_SECONDS =
864_000

Instance Attribute Summary collapse

Attributes included from Extensions::Credentiable

#credentials

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions::EnsureType

#ensure_type

Methods included from Extensions::MassAssignment

#initialize

Instance Attribute Details

#chargeObject

Set the charge



27
28
29
# File 'lib/pagseguro/subscription.rb', line 27

def charge
  @charge
end

#codeObject

The code of a created to the subscription, must be saved



42
43
44
# File 'lib/pagseguro/subscription.rb', line 42

def code
  @code
end

#dateObject

Set the date



15
16
17
# File 'lib/pagseguro/subscription.rb', line 15

def date
  @date
end

#last_event_dateObject

Set the last event date



24
25
26
# File 'lib/pagseguro/subscription.rb', line 24

def last_event_date
  @last_event_date
end

#nameObject

Set the name



12
13
14
# File 'lib/pagseguro/subscription.rb', line 12

def name
  @name
end

#payment_methodObject

Get the payment method



39
40
41
# File 'lib/pagseguro/subscription.rb', line 39

def payment_method
  @payment_method
end

#planObject

Set the plan



30
31
32
# File 'lib/pagseguro/subscription.rb', line 30

def plan
  @plan
end

#referenceObject

Set the reference



33
34
35
# File 'lib/pagseguro/subscription.rb', line 33

def reference
  @reference
end

#senderObject

Get the sender



36
37
38
# File 'lib/pagseguro/subscription.rb', line 36

def sender
  @sender
end

#statusObject

Set the status



21
22
23
# File 'lib/pagseguro/subscription.rb', line 21

def status
  @status
end

#trackerObject

Set the tracker



18
19
20
# File 'lib/pagseguro/subscription.rb', line 18

def tracker
  @tracker
end

Class Method Details

.find_by_code(code, options = {}) ⇒ Object

Find subscription by subscription code



74
75
76
# 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 = {}) ⇒ Object

Find subscription by notification code



69
70
71
# 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) ⇒ Object



101
102
103
# 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 = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# 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 = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# 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

Instance Method Details

#createObject



58
59
60
61
62
# 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

#errorsObject



64
65
66
# File 'lib/pagseguro/subscription.rb', line 64

def errors
  @errors ||= Errors.new
end

#update_attributes(attrs) ⇒ Object



54
55
56
# File 'lib/pagseguro/subscription.rb', line 54

def update_attributes(attrs)
  attrs.each {|name, value| send("#{name}=", value)  }
end