paymill_ruby 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +3 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +223 -0
  7. data/Rakefile +6 -0
  8. data/lib/paymill.rb +54 -0
  9. data/lib/paymill/errors.rb +10 -0
  10. data/lib/paymill/models/address.rb +13 -0
  11. data/lib/paymill/models/base.rb +50 -0
  12. data/lib/paymill/models/checksum.rb +40 -0
  13. data/lib/paymill/models/client.rb +24 -0
  14. data/lib/paymill/models/fee.rb +14 -0
  15. data/lib/paymill/models/invoice.rb +18 -0
  16. data/lib/paymill/models/merchant.rb +21 -0
  17. data/lib/paymill/models/offer.rb +27 -0
  18. data/lib/paymill/models/payment.rb +20 -0
  19. data/lib/paymill/models/payment_method.rb +18 -0
  20. data/lib/paymill/models/preauthorization.rb +25 -0
  21. data/lib/paymill/models/refund.rb +22 -0
  22. data/lib/paymill/models/shopping_cart_item.rb +13 -0
  23. data/lib/paymill/models/subscription.rb +143 -0
  24. data/lib/paymill/models/subscription_count.rb +18 -0
  25. data/lib/paymill/models/transaction.rb +27 -0
  26. data/lib/paymill/models/webhook.rb +37 -0
  27. data/lib/paymill/restful/methods.rb +134 -0
  28. data/lib/paymill/version.rb +3 -0
  29. data/paymill.gemspec +28 -0
  30. data/samples/authentication/authentication.rb +1 -0
  31. data/samples/clients/create_new_client.rb +4 -0
  32. data/samples/clients/export_clients_list.rb +1 -0
  33. data/samples/clients/get_client_details.rb +1 -0
  34. data/samples/clients/list_clients.rb +1 -0
  35. data/samples/clients/remove_client.rb +2 -0
  36. data/samples/clients/update_client.rb +4 -0
  37. data/samples/offers/create_new_offer.rb +7 -0
  38. data/samples/offers/export_offers_list.rb +1 -0
  39. data/samples/offers/get_offer_details.rb +1 -0
  40. data/samples/offers/list_offers.rb +1 -0
  41. data/samples/offers/remove_offer.rb +7 -0
  42. data/samples/offers/update_offer.rb +8 -0
  43. data/samples/payments/create_new_credit_card_payment_with_token.rb +1 -0
  44. data/samples/payments/create_new_credit_card_payment_with_token_and_client.rb +4 -0
  45. data/samples/payments/create_new_debit_payment_with_token.rb +1 -0
  46. data/samples/payments/create_new_debit_payment_with_token_and_client.rb +4 -0
  47. data/samples/payments/export_payments_list.rb +1 -0
  48. data/samples/payments/get_payment_details.rb +1 -0
  49. data/samples/payments/list_payments.rb +1 -0
  50. data/samples/payments/remove_payment.rb +2 -0
  51. data/samples/preauthorizations/create_new_preauthorization_with_payment.rb +8 -0
  52. data/samples/preauthorizations/create_new_preauthorization_with_token.rb +6 -0
  53. data/samples/preauthorizations/export_preauthorizations_list.rb +1 -0
  54. data/samples/preauthorizations/get_preauthorization_details.rb +1 -0
  55. data/samples/preauthorizations/list_preauthozizations.rb +1 -0
  56. data/samples/preauthorizations/remove_preauthorization.rb +2 -0
  57. data/samples/refunds/create_new_refund.rb +11 -0
  58. data/samples/refunds/export_refunds_list.rb +1 -0
  59. data/samples/refunds/get_refund_details.rb +1 -0
  60. data/samples/refunds/list_refunds.rb +1 -0
  61. data/samples/subscriptions/cancel_subscription.rb +2 -0
  62. data/samples/subscriptions/create_new_subscription_with_an_offer.rb +15 -0
  63. data/samples/subscriptions/create_new_subscription_with_an_offer_and_different_values.rb +19 -0
  64. data/samples/subscriptions/create_new_subscription_without_an_offer.rb +13 -0
  65. data/samples/subscriptions/delete_subscription.rb +2 -0
  66. data/samples/subscriptions/export_subscriptions_list.rb +1 -0
  67. data/samples/subscriptions/get_subscription_details.rb +1 -0
  68. data/samples/subscriptions/list_subscriptions.rb +1 -0
  69. data/samples/subscriptions/pause_subscription.rb +7 -0
  70. data/samples/subscriptions/update_subscription.rb +12 -0
  71. data/samples/subscriptions/update_subscription_amount.rb +7 -0
  72. data/samples/subscriptions/update_subscription_offer.rb +14 -0
  73. data/samples/transactions/create_new_transaction_with_app_fee.rb +8 -0
  74. data/samples/transactions/create_new_transaction_with_client_and_payment.rb +12 -0
  75. data/samples/transactions/create_new_transaction_with_payment.rb +7 -0
  76. data/samples/transactions/create_new_transaction_with_preauthorization.rb +10 -0
  77. data/samples/transactions/create_new_transaction_with_token.rb +6 -0
  78. data/samples/transactions/export_transactions_list.rb +1 -0
  79. data/samples/transactions/get_transaction_details_by_id.rb +1 -0
  80. data/samples/transactions/get_transaction_details_by_slv.rb +1 -0
  81. data/samples/transactions/list_transactions.rb +1 -0
  82. data/samples/transactions/upate_transaction.rb +3 -0
  83. data/samples/webhooks/create_new_email_webhook.rb +5 -0
  84. data/samples/webhooks/create_new_url_webhook.rb +4 -0
  85. data/samples/webhooks/export_webhooks_list.rb +1 -0
  86. data/samples/webhooks/get_webhook_details.rb +1 -0
  87. data/samples/webhooks/remove_webhook.rb +2 -0
  88. data/samples/webhooks/update_webhook.rb +3 -0
  89. data/spec/paymill/models/address_spec.rb +42 -0
  90. data/spec/paymill/models/checksum_spec.rb +77 -0
  91. data/spec/paymill/models/client_spec.rb +311 -0
  92. data/spec/paymill/models/offer_spec.rb +151 -0
  93. data/spec/paymill/models/payment_spec.rb +188 -0
  94. data/spec/paymill/models/preauthorization_spec.rb +180 -0
  95. data/spec/paymill/models/refund_spec.rb +90 -0
  96. data/spec/paymill/models/subscription_spec.rb +607 -0
  97. data/spec/paymill/models/transaction_spec.rb +226 -0
  98. data/spec/paymill/models/webhook_spec.rb +195 -0
  99. data/spec/spec_helper.rb +28 -0
  100. metadata +265 -0
@@ -0,0 +1,24 @@
1
+ module Paymill
2
+ class Client < Base
3
+ include Restful::Update
4
+ include Restful::Delete
5
+
6
+ attr_accessor :email, :description
7
+ attr_reader :payments, :subscriptions
8
+
9
+ protected
10
+ def self.create_with?( incoming_arguments )
11
+ return false if mandatory_arguments.select { |a| incoming_arguments.include? a }.size < mandatory_arguments.size
12
+ allowed_arguments.size == ( allowed_arguments | incoming_arguments ).size
13
+ end
14
+
15
+ def self.allowed_arguments
16
+ [:email, :description]
17
+ end
18
+
19
+ def self.mandatory_arguments
20
+ []
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module Paymill
2
+ class Fee
3
+
4
+ attr_accessor :type, :application, :payment, :amount, :currency, :billed_at
5
+
6
+ def initialize( json )
7
+ json.each_pair do |key, value|
8
+ instance_variable_set( "@#{key}", ( Integer( value ) rescue value ) )
9
+ end
10
+ @billed_at &&= Time.at( @billed_at )
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Paymill
2
+ class Invoice
3
+
4
+ attr_accessor :invoice_nr, :netto, :brutto, :status, :period_from, :last_reminder_date,
5
+ :period_until, :currency, :vat_rate, :billing_date, :invoice_type
6
+
7
+ def initialize( json )
8
+ json.each_pair do |key, value|
9
+ instance_variable_set( "@#{key}", ( Integer( value ) rescue value ) )
10
+ end
11
+ @period_from &&= Time.at( @period_from )
12
+ @period_until &&= Time.at( @period_until )
13
+ @billing_date &&= Time.at( @billing_date )
14
+ @last_reminder_date &&= Time.at( @last_reminder_date )
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Paymill
2
+ class Merchant
3
+
4
+ attr_accessor :identifier_key, :email, :locale, :country, :currencies, :methods
5
+
6
+ def initialize( json )
7
+ deserialize( json )
8
+ end
9
+
10
+ private
11
+ def deserialize( json )
12
+ case value.class.name
13
+ when 'Array'
14
+ instance_variable_set( "@#{key}s", value.map { |e| e } )
15
+ else
16
+ instance_variable_set( "@#{key}", (Integer( value ) rescue value) )
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module Paymill
2
+ class Offer < Base
3
+ include Restful::Update
4
+ include Restful::Delete
5
+
6
+ attr_reader :subscription_count
7
+ attr_accessor :name, :amount, :currency, :interval, :trial_period_days
8
+
9
+ def delete_with_subscriptions
10
+ delete( remove_with_subscriptions: true )
11
+ end
12
+
13
+ def delete_without_subscriptions
14
+ delete( remove_with_subscriptions: false )
15
+ end
16
+
17
+ protected
18
+ def self.allowed_arguments
19
+ [:amount, :currency, :interval, :name, :trial_period_days]
20
+ end
21
+
22
+ def self.mandatory_arguments
23
+ [:amount, :currency, :interval, :name]
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module Paymill
2
+ class Payment < Base
3
+ include Restful::Delete
4
+
5
+ attr_reader :type, :client, :card_type, :is_recurring, :is_usable_for_preauthorization,
6
+ :country, :expire_month, :expire_year, :card_holder, :last4,
7
+ :code, :holder, :account,
8
+ :iban, :bic
9
+
10
+ protected
11
+ def self.allowed_arguments
12
+ [:token, :client]
13
+ end
14
+
15
+ def self.mandatory_arguments
16
+ [:token]
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Paymill
2
+ class PaymentMethod
3
+
4
+ attr_accessor :type, :currency, :acquirer
5
+
6
+ def initialize( json )
7
+ deserialize( json )
8
+ end
9
+
10
+ private
11
+ def deserialize( json )
12
+ json.each_pair do |key, value|
13
+ instance_variable_set( "@#{key}", ( Integer( value ) rescue value ) )
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module Paymill
2
+ class Preauthorization < Base
3
+ include Restful::Delete
4
+
5
+ attr_reader :amount, :currency, :description, :status, :livemode, :payment, :client, :transaction
6
+
7
+ protected
8
+ def self.create_with?( incoming_arguments )
9
+ raise ArgumentError unless incoming_arguments.any? { |e| mutual_excluded_arguments.include? e } && ( incoming_arguments & mutual_excluded_arguments ).size == 1
10
+ super( incoming_arguments - mutual_excluded_arguments )
11
+ end
12
+
13
+ def self.mandatory_arguments
14
+ [:amount, :currency]
15
+ end
16
+
17
+ def self.allowed_arguments
18
+ [:amount, :currency, :description]
19
+ end
20
+
21
+ def self.mutual_excluded_arguments
22
+ [:token, :payment]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module Paymill
2
+ class Refund < Base
3
+
4
+ attr_reader :amount, :description, :transaction, :status, :livemode, :response_code
5
+
6
+ def self.create( transaction, attributes = {} )
7
+ raise ArgumentError unless create_with?( attributes.keys )
8
+ response = Paymill.request( Http.post( name.demodulize.tableize, transaction.id, Restful.normalize( attributes ) ) )
9
+ new( response['data'] )
10
+ end
11
+
12
+ protected
13
+ def self.mandatory_arguments
14
+ [:amount]
15
+ end
16
+
17
+ def self.allowed_arguments
18
+ [:amount, :description]
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module Paymill
2
+ class ShoppingCartItem
3
+ attr_accessor :name, :amount, :quantity, :item_number, :url, :description
4
+
5
+ def initialize( arguments = {} )
6
+ arguments.each do |key, value|
7
+ raise ArgumentError.new( "parameter #{key} is not allowed" ) unless ShoppingCartItem.instance_methods( false ).include? key
8
+ instance_variable_set( "@#{key}", ( Integer( value ) rescue value ) )
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,143 @@
1
+ module Paymill
2
+ class Subscription < Base
3
+ include Restful::Update
4
+ include Restful::Delete
5
+
6
+ attr_reader :livemode, :temp_amount, :trial_start, :end_of_period, :next_capture_at, :canceled_at, :currency,
7
+ :is_canceled, :is_deleted, :status, :client, :interval, :payment, :name, :mandate_reference
8
+ attr_accessor :amount, :offer, :trial_end, :period_of_validity
9
+
10
+ def currency=( currency )
11
+ @offer = nil
12
+ @amount = nil
13
+ @currency = currency
14
+ end
15
+
16
+ def name=( name )
17
+ @offer = nil
18
+ @amount = nil
19
+ @name = name
20
+ end
21
+
22
+ def interval=( interval )
23
+ @offer = nil
24
+ @amount = nil
25
+ @interval = interval
26
+ end
27
+
28
+ def payment=( payment )
29
+ @offer = nil
30
+ @amount = nil
31
+ @payment = payment
32
+ end
33
+
34
+ def update_amount_once( amount )
35
+ update_amount( amount, 0 )
36
+ end
37
+
38
+ def update_amount_permanently( amount )
39
+ update_amount( amount, 1 )
40
+ end
41
+
42
+ def update_offer_without_changes( offer )
43
+ update_offer( offer, 0 )
44
+ end
45
+
46
+ def update_offer_with_refund( offer )
47
+ update_offer( offer, 1 )
48
+ end
49
+
50
+ def update_offer_with_refund_and_capture_date( offer )
51
+ update_offer( offer, 1 )
52
+ end
53
+
54
+ def stop_trial_period()
55
+ @offer = nil
56
+ @amount = nil
57
+ @trial_end = nil
58
+ update( trial_end: false )
59
+ end
60
+
61
+ def unlimit()
62
+ @offer = nil
63
+ @amount = nil
64
+ @period_of_validity = 'remove'
65
+ update()
66
+ end
67
+
68
+ def limit( limit )
69
+ @offer = nil
70
+ @amount = nil
71
+ @period_of_validity = limit
72
+ update()
73
+ end
74
+
75
+ def pause()
76
+ @offer = nil
77
+ @amount = nil
78
+ update( pause: true )
79
+ end
80
+
81
+ def play()
82
+ @offer = nil
83
+ @amount = nil
84
+ update( pause: false )
85
+ end
86
+
87
+ def cancel()
88
+ delete( remove: false )
89
+ end
90
+
91
+ def remove()
92
+ delete( remove: true )
93
+ end
94
+
95
+ protected
96
+ def self.create_with?( incoming_arguments )
97
+ raise ArgumentError unless incoming_arguments.include?( :offer ) || (mutual_excluded_arguments.last - incoming_arguments).empty?
98
+ super( incoming_arguments - mutual_excluded_arguments.flatten )
99
+ end
100
+
101
+ def self.mandatory_arguments
102
+ [:payment]
103
+ end
104
+
105
+ def self.allowed_arguments
106
+ [:offer, :payment, :client, :amount, :currency, :interval, :name, :period_of_validity, :start_at, :mandate_reference]
107
+ end
108
+
109
+ def parse_timestamps
110
+ @trial_end &&= Time.at( @trial_end )
111
+ @canceled_at &&= Time.at( @canceled_at )
112
+ @trial_start &&= Time.at( @trial_start)
113
+ @canceled_at &&= Time.at( @canceled_at )
114
+ @end_of_period &&= Time.at( @end_of_period )
115
+ @next_capture_at &&= Time.at( @next_capture_at )
116
+ super
117
+ end
118
+
119
+ def self.mutual_excluded_arguments
120
+ [[:offer], [:amount, :currency, :interval]]
121
+ end
122
+
123
+ private
124
+ def update_amount( amount, flag)
125
+ raise ArgumentError( 'amount_change_type should be 0 or 1' ) unless [0, 1].include?( flag )
126
+ @offer = nil
127
+ @amount = amount
128
+ update( amount_change_type: flag )
129
+ end
130
+
131
+ def update_offer( offer, flag )
132
+ raise ArgumentError( 'offer_change_type should be between 0 and 2' ) unless (0..2).include?( flag )
133
+ @currency = nil
134
+ @name = nil
135
+ @interval = nil
136
+ @amount = nil
137
+ @payment = nil
138
+ @offer = offer
139
+ update( offer_change_type: 1 )
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,18 @@
1
+ module Paymill
2
+ class SubscriptionCount
3
+
4
+ attr_accessor :active, :inactive
5
+
6
+ def initialize( json )
7
+ deserialize( json )
8
+ end
9
+
10
+ private
11
+ def deserialize( json )
12
+ json.each_pair do |key, value|
13
+ instance_variable_set( "@#{key}", ( Integer( value ) rescue value ) )
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module Paymill
2
+ class Transaction < Base
3
+ include Restful::Update
4
+
5
+ attr_accessor :description
6
+ attr_reader :amount, :client, :currency, :origin_amount, :status, :livemode, :refunds,
7
+ :response_code, :is_fraud, :short_id, :fees, :invoices, :payment, :preauthorization, :mandate_reference
8
+
9
+ protected
10
+ def self.create_with?( incoming_arguments )
11
+ raise ArgumentError unless incoming_arguments.any? { |e| mutual_excluded_arguments.include? e } && ( incoming_arguments & mutual_excluded_arguments ).size == 1
12
+ super( incoming_arguments - mutual_excluded_arguments )
13
+ end
14
+
15
+ def self.mandatory_arguments
16
+ [:amount, :currency]
17
+ end
18
+
19
+ def self.allowed_arguments
20
+ [:amount, :client, :currency, :description, :preauthorization, :fee_amount, :fee_payment, :fee_currency, :mandate_reference]
21
+ end
22
+
23
+ def self.mutual_excluded_arguments
24
+ [:token, :payment, :preauthorization]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module Paymill
2
+ class Webhook < Base
3
+ include Restful::Update
4
+ include Restful::Delete
5
+
6
+ attr_reader :url, :email, :livemode
7
+ attr_accessor :event_types, :active
8
+
9
+ def email=( email )
10
+ @url = nil
11
+ @email = email
12
+ end
13
+
14
+ def url=( url )
15
+ @url = url
16
+ @email = nil
17
+ end
18
+
19
+ protected
20
+ def self.create_with?( incoming_arguments )
21
+ raise ArgumentError unless incoming_arguments.any? { |e| mutual_excluded_arguments.include? e } && ( incoming_arguments & mutual_excluded_arguments ).size == 1
22
+ super( incoming_arguments - mutual_excluded_arguments )
23
+ end
24
+
25
+ def self.mandatory_arguments
26
+ [:event_types]
27
+ end
28
+
29
+ def self.allowed_arguments
30
+ [:event_types, :active]
31
+ end
32
+
33
+ def self.mutual_excluded_arguments
34
+ [:email, :url]
35
+ end
36
+ end
37
+ end