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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +223 -0
- data/Rakefile +6 -0
- data/lib/paymill.rb +54 -0
- data/lib/paymill/errors.rb +10 -0
- data/lib/paymill/models/address.rb +13 -0
- data/lib/paymill/models/base.rb +50 -0
- data/lib/paymill/models/checksum.rb +40 -0
- data/lib/paymill/models/client.rb +24 -0
- data/lib/paymill/models/fee.rb +14 -0
- data/lib/paymill/models/invoice.rb +18 -0
- data/lib/paymill/models/merchant.rb +21 -0
- data/lib/paymill/models/offer.rb +27 -0
- data/lib/paymill/models/payment.rb +20 -0
- data/lib/paymill/models/payment_method.rb +18 -0
- data/lib/paymill/models/preauthorization.rb +25 -0
- data/lib/paymill/models/refund.rb +22 -0
- data/lib/paymill/models/shopping_cart_item.rb +13 -0
- data/lib/paymill/models/subscription.rb +143 -0
- data/lib/paymill/models/subscription_count.rb +18 -0
- data/lib/paymill/models/transaction.rb +27 -0
- data/lib/paymill/models/webhook.rb +37 -0
- data/lib/paymill/restful/methods.rb +134 -0
- data/lib/paymill/version.rb +3 -0
- data/paymill.gemspec +28 -0
- data/samples/authentication/authentication.rb +1 -0
- data/samples/clients/create_new_client.rb +4 -0
- data/samples/clients/export_clients_list.rb +1 -0
- data/samples/clients/get_client_details.rb +1 -0
- data/samples/clients/list_clients.rb +1 -0
- data/samples/clients/remove_client.rb +2 -0
- data/samples/clients/update_client.rb +4 -0
- data/samples/offers/create_new_offer.rb +7 -0
- data/samples/offers/export_offers_list.rb +1 -0
- data/samples/offers/get_offer_details.rb +1 -0
- data/samples/offers/list_offers.rb +1 -0
- data/samples/offers/remove_offer.rb +7 -0
- data/samples/offers/update_offer.rb +8 -0
- data/samples/payments/create_new_credit_card_payment_with_token.rb +1 -0
- data/samples/payments/create_new_credit_card_payment_with_token_and_client.rb +4 -0
- data/samples/payments/create_new_debit_payment_with_token.rb +1 -0
- data/samples/payments/create_new_debit_payment_with_token_and_client.rb +4 -0
- data/samples/payments/export_payments_list.rb +1 -0
- data/samples/payments/get_payment_details.rb +1 -0
- data/samples/payments/list_payments.rb +1 -0
- data/samples/payments/remove_payment.rb +2 -0
- data/samples/preauthorizations/create_new_preauthorization_with_payment.rb +8 -0
- data/samples/preauthorizations/create_new_preauthorization_with_token.rb +6 -0
- data/samples/preauthorizations/export_preauthorizations_list.rb +1 -0
- data/samples/preauthorizations/get_preauthorization_details.rb +1 -0
- data/samples/preauthorizations/list_preauthozizations.rb +1 -0
- data/samples/preauthorizations/remove_preauthorization.rb +2 -0
- data/samples/refunds/create_new_refund.rb +11 -0
- data/samples/refunds/export_refunds_list.rb +1 -0
- data/samples/refunds/get_refund_details.rb +1 -0
- data/samples/refunds/list_refunds.rb +1 -0
- data/samples/subscriptions/cancel_subscription.rb +2 -0
- data/samples/subscriptions/create_new_subscription_with_an_offer.rb +15 -0
- data/samples/subscriptions/create_new_subscription_with_an_offer_and_different_values.rb +19 -0
- data/samples/subscriptions/create_new_subscription_without_an_offer.rb +13 -0
- data/samples/subscriptions/delete_subscription.rb +2 -0
- data/samples/subscriptions/export_subscriptions_list.rb +1 -0
- data/samples/subscriptions/get_subscription_details.rb +1 -0
- data/samples/subscriptions/list_subscriptions.rb +1 -0
- data/samples/subscriptions/pause_subscription.rb +7 -0
- data/samples/subscriptions/update_subscription.rb +12 -0
- data/samples/subscriptions/update_subscription_amount.rb +7 -0
- data/samples/subscriptions/update_subscription_offer.rb +14 -0
- data/samples/transactions/create_new_transaction_with_app_fee.rb +8 -0
- data/samples/transactions/create_new_transaction_with_client_and_payment.rb +12 -0
- data/samples/transactions/create_new_transaction_with_payment.rb +7 -0
- data/samples/transactions/create_new_transaction_with_preauthorization.rb +10 -0
- data/samples/transactions/create_new_transaction_with_token.rb +6 -0
- data/samples/transactions/export_transactions_list.rb +1 -0
- data/samples/transactions/get_transaction_details_by_id.rb +1 -0
- data/samples/transactions/get_transaction_details_by_slv.rb +1 -0
- data/samples/transactions/list_transactions.rb +1 -0
- data/samples/transactions/upate_transaction.rb +3 -0
- data/samples/webhooks/create_new_email_webhook.rb +5 -0
- data/samples/webhooks/create_new_url_webhook.rb +4 -0
- data/samples/webhooks/export_webhooks_list.rb +1 -0
- data/samples/webhooks/get_webhook_details.rb +1 -0
- data/samples/webhooks/remove_webhook.rb +2 -0
- data/samples/webhooks/update_webhook.rb +3 -0
- data/spec/paymill/models/address_spec.rb +42 -0
- data/spec/paymill/models/checksum_spec.rb +77 -0
- data/spec/paymill/models/client_spec.rb +311 -0
- data/spec/paymill/models/offer_spec.rb +151 -0
- data/spec/paymill/models/payment_spec.rb +188 -0
- data/spec/paymill/models/preauthorization_spec.rb +180 -0
- data/spec/paymill/models/refund_spec.rb +90 -0
- data/spec/paymill/models/subscription_spec.rb +607 -0
- data/spec/paymill/models/transaction_spec.rb +226 -0
- data/spec/paymill/models/webhook_spec.rb +195 -0
- data/spec/spec_helper.rb +28 -0
- metadata +265 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
module Paymill
|
2
|
+
module Restful
|
3
|
+
|
4
|
+
module All
|
5
|
+
def all( arguments = {} )
|
6
|
+
unless arguments.empty?
|
7
|
+
order = "#{arguments[:order].map{ |e| "order=#{e.id2name}" }.join( '&' )}" if arguments[:order]
|
8
|
+
filters = arguments[:filters].map{ |hash| hash.map{ |key, value| "#{key.id2name}=#{value.gsub( ' ', '+' ) }" }.join( '&' ) } if arguments[:filters]
|
9
|
+
count = "count=#{arguments[:count]}" if arguments[:count]
|
10
|
+
offset = "offset=#{arguments[:offset]}" if arguments[:offset]
|
11
|
+
arguments = "?#{[order, filters, offset, count].reject { |e| e.nil? }.join( '&' )}"
|
12
|
+
else
|
13
|
+
arguments = ''
|
14
|
+
end
|
15
|
+
|
16
|
+
response = Paymill.request( Http.all( Restful.demodulize_and_tableize( name ), arguments ) )
|
17
|
+
enrich_array_with_data_count( response['data'].map!{ |element| new( element ) }, response['data_count'] )
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def enrich_array_with_data_count( array, data_count )
|
22
|
+
array.instance_variable_set( '@data_count', data_count )
|
23
|
+
def array.data_count
|
24
|
+
@data_count
|
25
|
+
end
|
26
|
+
array
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Find
|
31
|
+
def find( model )
|
32
|
+
model = model.id if model.is_a? self
|
33
|
+
response = Paymill.request( Http.get( Restful.demodulize_and_tableize( name ), model ) )
|
34
|
+
new( response['data'] )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Create
|
39
|
+
def create( arguments = {} )
|
40
|
+
raise ArgumentError unless create_with?( arguments.keys )
|
41
|
+
response = Paymill.request( Http.post( Restful.demodulize_and_tableize( name ), Restful.normalize( arguments ) ) )
|
42
|
+
new( response['data'] )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module Update
|
47
|
+
def update( arguments = {} )
|
48
|
+
arguments.merge! public_methods( false ).grep( /.*=/ ).map{ |m| m = m.id2name.chop; { m => send( m ) } }.reduce( :merge )
|
49
|
+
|
50
|
+
response = Paymill.request( Http.put( Restful.demodulize_and_tableize( self.class.name ), self.id, Restful.normalize( arguments ) ) )
|
51
|
+
source = self.class.new( response['data'] )
|
52
|
+
self.instance_variables.each { |key| self.instance_variable_set( key, source.instance_variable_get( key ) ) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Delete
|
57
|
+
def delete( arguments = {} )
|
58
|
+
response = Paymill.request( Http.delete( Restful.demodulize_and_tableize( self.class.name ), self.id, arguments ) )
|
59
|
+
return self.class.new( response['data'] ) if self.class.name.eql? 'Paymill::Subscription'
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def self.demodulize_and_tableize( name )
|
66
|
+
"#{name.split('::').last.downcase}s"
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.normalize( parameters = {} )
|
70
|
+
attributes = {}.compare_by_identity
|
71
|
+
parameters.each do |key, value|
|
72
|
+
if value.is_a? Array
|
73
|
+
value.each.with_index do |e, index|
|
74
|
+
if e.is_a? ShoppingCartItem
|
75
|
+
e.instance_variables.each do |var|
|
76
|
+
attributes["items[#{index}][#{var.to_s[1..-1]}]"] = e.instance_variable_get( var ) unless e.instance_variable_get( var ).to_s.empty?
|
77
|
+
end
|
78
|
+
else
|
79
|
+
attributes["#{key.to_s}[]"] = e
|
80
|
+
end
|
81
|
+
end
|
82
|
+
elsif value.is_a? Base
|
83
|
+
attributes[key.to_s] = value.id
|
84
|
+
elsif value.is_a? Time
|
85
|
+
attributes[key.to_s] = value.to_i
|
86
|
+
elsif value.is_a? Address
|
87
|
+
value.instance_variables.each do |var|
|
88
|
+
attributes["#{key.to_s}[#{var.to_s[1..-1]}]"] = value.instance_variable_get( var ) unless value.instance_variable_get( var ).to_s.empty?
|
89
|
+
end
|
90
|
+
else
|
91
|
+
attributes[key.to_s] = value unless value.nil?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
attributes
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
module Http
|
99
|
+
def self.all( endpoint, arguments )
|
100
|
+
request = Net::HTTP::Get.new( "/#{Paymill.api_version}/#{endpoint}#{arguments}" )
|
101
|
+
request.basic_auth( Paymill.api_key, '' )
|
102
|
+
request
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.get( endpoint, id )
|
106
|
+
request = Net::HTTP::Get.new( "/#{Paymill.api_version}/#{endpoint}/#{id}" )
|
107
|
+
request.basic_auth( Paymill.api_key, '' )
|
108
|
+
request
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.post( endpoint, id = nil, arguments )
|
112
|
+
request = Net::HTTP::Post.new( "/#{Paymill.api_version}/#{endpoint}/#{id}" )
|
113
|
+
request.basic_auth( Paymill.api_key, '' )
|
114
|
+
request.set_form_data( arguments )
|
115
|
+
request
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.put( endpoint, id, arguments )
|
119
|
+
request = Net::HTTP::Put.new( "/#{Paymill.api_version}/#{endpoint}/#{id}" )
|
120
|
+
request.basic_auth( Paymill.api_key, '' )
|
121
|
+
request.set_form_data( arguments )
|
122
|
+
request
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.delete( endpoint, id, arguments )
|
126
|
+
arguments = arguments.map { |key, value| "#{key.id2name}=#{value}" }.join( '&' )
|
127
|
+
arguments = "?#{arguments}" unless arguments.empty?
|
128
|
+
request = Net::HTTP::Delete.new( "/#{Paymill.api_version}/#{endpoint}/#{id}#{arguments}" )
|
129
|
+
request.basic_auth( Paymill.api_key, '' )
|
130
|
+
# request.set_form_data( arguments ) unless arguments.empty?
|
131
|
+
request
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/paymill.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paymill/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paymill_ruby"
|
8
|
+
spec.version = Paymill::VERSION
|
9
|
+
spec.authors = ["Vassil Nikolov"]
|
10
|
+
spec.email = ["vassil.nikolov@qaiware.com"]
|
11
|
+
spec.summary = %q{The official ruby wrapper for PAYMILL's API.}
|
12
|
+
spec.homepage = "https://github.com/paymill/paymill-ruby"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0") - ['.gitignore', '.travis.yml', '.rspec']
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "activesupport", "~> 4.2"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
24
|
+
spec.add_development_dependency "vcr", "~> 2.9"
|
25
|
+
spec.add_development_dependency "webmock", "~> 1.20"
|
26
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
27
|
+
spec.add_development_dependency "guard-rspec", "~> 4.3"
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill.api_key = "<YOUR_PRIVATE_KEY>"
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not implemented yet
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Client.find('client_88a388d9dd48f86c3136')
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Client.all
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not implemented yet
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Offer.find('offer_40237e20a7d5a231d99b')
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Offer.all()
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Payment.create( token: '098f6bcd4621d373cade4e832627b4f6' )
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Payment.create( token: '12a46bcd462sd3r3care4e8336ssb4f5' )
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not yet implemented
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Payment.find( 'pay_3af44644dd6d25c820a8' )
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Payment.all
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not implemented yet
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Preauthorization.find('preauth_31eb90495837447f76b7')
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Preauthorization.all()
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not implemented yet
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Refund.find('refund_87bc404a95d5ce616049')
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Refund.all()
|
@@ -0,0 +1,15 @@
|
|
1
|
+
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')
|
2
|
+
offer = Paymill::Offer.create(
|
3
|
+
amount: 3333,
|
4
|
+
currency: 'EUR',
|
5
|
+
interval: '1 WEEK',
|
6
|
+
name: 'Nerd Special',
|
7
|
+
trial_period_days: 30
|
8
|
+
)
|
9
|
+
|
10
|
+
Paymill::Subscription.create(
|
11
|
+
payment: payment,
|
12
|
+
offer: offer,
|
13
|
+
period_of_validity: '2 YEAR',
|
14
|
+
start_at: 2.days.from_now
|
15
|
+
)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')
|
2
|
+
offer = Paymill::Offer.create(
|
3
|
+
amount: 4200,
|
4
|
+
currency: 'EUR',
|
5
|
+
interval: '1 MONTH',
|
6
|
+
name: 'Nerd Special',
|
7
|
+
trial_period_days: 30
|
8
|
+
)
|
9
|
+
|
10
|
+
Paymill::Subscription.create(
|
11
|
+
payment: payment,
|
12
|
+
offer: offer,
|
13
|
+
amount: 3000,
|
14
|
+
currency: 'EUR',
|
15
|
+
interval: '1 week, monday',
|
16
|
+
name: 'Example Subscription',
|
17
|
+
period_of_validity: '2 YEAR',
|
18
|
+
start_at: 2.days.from_now
|
19
|
+
)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
client = Paymill::Client.create(email: 'client@example.com')
|
2
|
+
payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6', client: client)
|
3
|
+
|
4
|
+
Paymill::Subscription.create(
|
5
|
+
payment: payment,
|
6
|
+
client: client,
|
7
|
+
name: 'Example Subscription',
|
8
|
+
amount: 3000,
|
9
|
+
currency: 'EUR',
|
10
|
+
interval: '1 week,monday',
|
11
|
+
period_of_validity: '2 YEAR',
|
12
|
+
start_at: 2.days.from_now
|
13
|
+
)
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not implemented yet
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Subscription.find("sub_dc180b755d10da324864")
|
@@ -0,0 +1 @@
|
|
1
|
+
Paymill::Subscription.all()
|
@@ -0,0 +1,12 @@
|
|
1
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
2
|
+
subscription.payment = 'pay_95ba26ba2c613ebb0ca8'
|
3
|
+
subscription.currency = 'USD'
|
4
|
+
subscription.interval = '1 month,friday'
|
5
|
+
subscription.name = 'Changed Subscription'
|
6
|
+
subscription.trial_end = false
|
7
|
+
subscription.update
|
8
|
+
|
9
|
+
# for limit / unlimit use
|
10
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
11
|
+
subscription.unlimit
|
12
|
+
subscription.limit('12 MONTH')
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#amount temporary:
|
2
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
3
|
+
subscription.update_amount_once(1234)
|
4
|
+
|
5
|
+
#amount permanently:
|
6
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
7
|
+
subscription.update_amount_permanently(1234)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#offer with no refund and unchanged capture date:
|
2
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
3
|
+
offer = Offer.create(name: 'Foo', amount: 4990, currency: 'EUR', interval: '2 WEEK')
|
4
|
+
subscription.update_offer_without_changes(offer)
|
5
|
+
|
6
|
+
#offer with refund and unchanged capture date:
|
7
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
8
|
+
offer = Offer.create(name: 'Foo', amount: 4990, currency: 'EUR', interval: '2 WEEK')
|
9
|
+
subscription.update_offer_with_refund(offer)
|
10
|
+
|
11
|
+
#offer with refund and capture date:
|
12
|
+
subscription = Paymill::Subscription.find('sub_dea86e5c65b2087202e3')
|
13
|
+
offer = Offer.create(name: 'Foo', amount: 4990, currency: 'EUR', interval: '2 WEEK')
|
14
|
+
subscription.update_offer_with_refund_and_capture_date(offer)
|