Class: MC2P::NotificationData

Inherits:
Object
  • Object
show all
Defined in:
lib/notification.rb

Overview

Notification data - class to manage notification from MyChoice2Pay

Instance Method Summary collapse

Constructor Details

#initialize(json_body, mc2p) ⇒ NotificationData

Initializes a notification data Params:

json_body

content of request from MyChoice2Pay

mc2p

MC2PClient



8
9
10
11
# File 'lib/notification.rb', line 8

def initialize(json_body, mc2p)
  @json_body = json_body
  @mc2p = mc2p
end

Instance Method Details

#actionObject

Returns: action executed



34
35
36
# File 'lib/notification.rb', line 34

def action
  @json_body['action']
end

#order_idObject

Returns: order_id sent when payment was created



29
30
31
# File 'lib/notification.rb', line 29

def order_id
  @json_body['order_id']
end

#saleObject

Returns: sale generated when payment was paid



59
60
61
62
63
64
65
66
# File 'lib/notification.rb', line 59

def sale
  ret = nil
  if @json_body.include?('sale_id')
    ret = @mc2p.sale('id' => @json_body['sale_id'])
    ret.retrieve
  end
  ret
end

#sale_actionObject

Returns: action of sale executed



69
70
71
# File 'lib/notification.rb', line 69

def sale_action
  @json_body['sale_action']
end

#statusObject

Returns: status of payment



14
15
16
# File 'lib/notification.rb', line 14

def status
  @json_body['status']
end

#subscriptionObject

Returns: subscription generated when payment was created



49
50
51
52
53
54
55
56
# File 'lib/notification.rb', line 49

def subscription
  ret = nil
  if type == 'S'
    ret = @mc2p.subscription('id' => @json_body['id'])
    ret.retrieve
  end
  ret
end

#subscription_statusObject

Returns: status of subscription



19
20
21
# File 'lib/notification.rb', line 19

def subscription_status
  @json_body['subscription_status']
end

#transactionObject

Returns: transaction generated when payment was created



39
40
41
42
43
44
45
46
# File 'lib/notification.rb', line 39

def transaction
  ret = nil
  if type == 'P'
    ret = @mc2p.transaction('id' => @json_body['id'])
    ret.retrieve
  end
  ret
end

#typeObject

Returns: type of payment



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

def type
  @json_body['type']
end