paymill_ruby 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e883a63ce492c9a8875d002cf089970a8368a9eb
|
4
|
+
data.tar.gz: c7393c11f67b212890afef61f1320c2a4d4312c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53000c3a307360159a9b573d4ebdaa94b20bc0e918e4108e086888614595eabede434c2216577a4d4493017b85ab994473f562ccdee6f4318f3ff69db153a84f
|
7
|
+
data.tar.gz: 412035f597b59608248c5c2787554d7fe4e4ecde3f522467b781f97c2d92ebc4ea2a065e9d8fcef0089ba873ac7fe997f90b7259547ff7d6417001a2e498477e
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 BSc Vassil Nikolov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
![PAYMILL icon](https://static.paymill.com/r/335f99eb3914d517bf392beb1adaf7cccef786b6/img/logo-download_Light.png)
|
2
|
+
|
3
|
+
paymill-ruby
|
4
|
+
============
|
5
|
+
|
6
|
+
Ruby wrapper for PAYMILL API forked by [dkd's paymill-ruby](https://github.com/dkd/paymill-ruby)
|
7
|
+
|
8
|
+
[![Build Status](https://travis-ci.org/paymill/paymill-ruby.svg)](https://travis-ci.org/paymill/paymill-ruby) [![Code Climate](https://codeclimate.com/github/paymill/paymill-ruby/badges/gpa.svg)](https://codeclimate.com/github/paymill/paymill-ruby)
|
9
|
+
|
10
|
+
Getting started
|
11
|
+
===============
|
12
|
+
|
13
|
+
- If you are not familiar with PAYMILL, start with the [documentation](https://www.paymill.com/en-gb/documentation-3/).
|
14
|
+
- Install the latest release.
|
15
|
+
- Check the API [reference](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/).
|
16
|
+
- Check the specification examples.
|
17
|
+
- Take a look at the [change log](./CHANGELOG.md) for recent updates and improvements.
|
18
|
+
|
19
|
+
Installation
|
20
|
+
============
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'paymill_ruby', '~> 1.0'
|
26
|
+
```
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
```
|
31
|
+
$ bundle
|
32
|
+
```
|
33
|
+
|
34
|
+
The paymill gem is tested on Ruby 1.9.3, 2.0.0, 2.1.0, 2.1.3 and 2.1.5. It requires ruby version 1.9.3+
|
35
|
+
|
36
|
+
Usage
|
37
|
+
=====
|
38
|
+
|
39
|
+
Initialize the library by providing your api key:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'paymill'
|
43
|
+
|
44
|
+
Paymill.api_key = '<YOUR PRIVATE API KEY>'
|
45
|
+
```
|
46
|
+
|
47
|
+
or by reading it from the envirounment variables
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'paymill'
|
51
|
+
|
52
|
+
Paymill.api_key = ENV['PAYMILL_API_TEST_KEY']
|
53
|
+
```
|
54
|
+
|
55
|
+
Clients
|
56
|
+
-------
|
57
|
+
|
58
|
+
#### Creating clients
|
59
|
+
|
60
|
+
Creating via factory method **create**, which expects an optional hash as arguments. If some of the required attributes are missing the method will throw **ArgumentError**.
|
61
|
+
|
62
|
+
With a hash of optional arguments:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
client = Paymill::Client.create( email: 'john.rambo@qaiware.com', description: 'Main caracter in First Blood' )
|
66
|
+
```
|
67
|
+
|
68
|
+
Without mandatory arguments:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
client = Paymill::Client.create
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Find existing client
|
75
|
+
|
76
|
+
You can retrieve an object by using the **find** method with an object id:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
client = Paymill::Client.find( 'client_b54ff8b3811e06c02e14' )
|
80
|
+
```
|
81
|
+
|
82
|
+
or with the instance itself:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
client = Paymill::Client.find( client )
|
86
|
+
```
|
87
|
+
|
88
|
+
#### Update client
|
89
|
+
|
90
|
+
Update is done by modifying the instance variables of the object. The object itself provides accessor methods only for properties which can be updated.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
client = Paymill::Client.find( 'client_b54ff8b3811e06c02e14' )
|
94
|
+
|
95
|
+
client.email = 'john.rambo.2@qaiware.com'
|
96
|
+
client.description = 'Main caracter in First Blood II'
|
97
|
+
|
98
|
+
client.update
|
99
|
+
```
|
100
|
+
|
101
|
+
#### Deleting client
|
102
|
+
|
103
|
+
You may delete objects by calling the its instance method **delete**. The delete method will return <code>nil</code> when the given object is removed successfully.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
client = Paymill::Client.find( 'client_b54ff8b3811e06c02e14' )
|
107
|
+
client.delete
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Retrieving lists
|
111
|
+
|
112
|
+
To retrieve a list you may simply use the **all** class method
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
clients = Paymill::Client.all
|
116
|
+
```
|
117
|
+
|
118
|
+
You may provide filter, order, offset and count parameters to list method
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
clients = Paymill::Client.all( order: [:email, :created_at_desc], count: 30, offset: 10, filters: [email: 'john.rambo@qaiware.com', created_at: "#{4.days.ago.to_i}-#{2.days.ago.to_i}"] )
|
122
|
+
```
|
123
|
+
|
124
|
+
Offer
|
125
|
+
-----
|
126
|
+
|
127
|
+
#### Update offer
|
128
|
+
|
129
|
+
When you want to update the offer and to apply the new changes to its subscriptions you can pass an additional parameter <code>update_subscriptions</code> set to <code>true</code> to its instance method **update**
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
offer = Offer.find( 'offer_b54ff8b3811e06c02e14' )
|
133
|
+
offer.amount = 1000
|
134
|
+
|
135
|
+
offer.update( update_subscriptions: true )
|
136
|
+
```
|
137
|
+
|
138
|
+
#### Deleting offer
|
139
|
+
|
140
|
+
To delete an offer and its corresponding subscriptions call
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
offer = Offer.find( 'offer_b54ff8b3811e06c02e14' )
|
144
|
+
offer.delete_with_subscriptions()
|
145
|
+
```
|
146
|
+
|
147
|
+
To delete an offer but leave its corresponding subscriptions call
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
offer = Offer.find( 'offer_b54ff8b3811e06c02e14' )
|
151
|
+
offer.delete_without_subscriptions
|
152
|
+
```
|
153
|
+
|
154
|
+
To delete an offer and its corresponding subscriptions you can call the instance method **delete** with an argument <code>remove_with_subscriptions</code> set to <code>true</code>
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
offer = Offer.find( 'offer_b54ff8b3811e06c02e14' )
|
158
|
+
offer.delete( remove_with_subscriptions: true )
|
159
|
+
```
|
160
|
+
|
161
|
+
Refund
|
162
|
+
------
|
163
|
+
|
164
|
+
#### Creating refunds
|
165
|
+
|
166
|
+
To create a refund you have to pass a transaction, which you want to be refunded.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
transaction = Transaction.create( token: '098f6bcd4621d373cade4e832627b4f6', amount: 990, currency: 'EUR' )
|
170
|
+
refund = Refund.create( transaction, amount: 100 )
|
171
|
+
```
|
172
|
+
|
173
|
+
Checksum
|
174
|
+
--------
|
175
|
+
|
176
|
+
#### Creating plain checksum
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
Checksum.create( checksum_type: 'paypal', amount: 4200, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel' )
|
180
|
+
```
|
181
|
+
|
182
|
+
#### Creating checksum with address
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
billing_address = Address.new( name: 'Primary', street_address: 'Rambo Str.', street_address_addition: '', city: 'Sofia', state: 'Sofia', postal_code: 1234, country: 'BG', phone: '088 41 555 27' )
|
186
|
+
Checksum.create( checksum_type: 'paypal', amount: 4200, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel', billing_address: billing_address )
|
187
|
+
```
|
188
|
+
|
189
|
+
#### Creating checksum with items
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
rambo_poster = ShoppingCartItem.new( name: "Rambo Poster", description: "John J. Rambo", amount: 2200, quantity: 3, item_number: "898-24342-343", url: "http://www.store.com/items/posters/12121-rambo" )
|
193
|
+
comando_poster = ShoppingCartItem.new( name: "Comando Poster", description: "John Matrix", amount: 3100, quantity: 1, item_number: "898-24342-341", url: "http://www.store.com/items/posters/12121-comando" )
|
194
|
+
Checksum.create( checksum_type: 'paypal', amount: 9700, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel', items: [rambo_poster, comando_poster] )
|
195
|
+
```
|
196
|
+
|
197
|
+
#### Creating checksum with fee
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
Checksum.create( checksum_type: 'paypal', amount: 9700, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel', fee_amount: 100, fee_payment: 'pay_3af44644dd6d25c820a8', fee_currency: 'EUR', app_id: '8fh98hfd828ej2e09dk0hf9' )
|
201
|
+
```
|
202
|
+
|
203
|
+
Changelog
|
204
|
+
=========
|
205
|
+
|
206
|
+
### 1.0.0
|
207
|
+
* fix [issue #6](https://github.com/paymill/paymill-ruby/issues/6) Add new parameter mandate_reference
|
208
|
+
* fix [issue #7](https://github.com/paymill/paymill-ruby/issues/7) ActiveSupport 4.1 requirement
|
209
|
+
* fix [issue #8](https://github.com/paymill/paymill-ruby/issues/8) No access to iban and bic
|
210
|
+
* fix [issue #9](https://github.com/paymill/paymill-ruby/issues/9) Add explanation on how to run the spec
|
211
|
+
* Add Checksum, Address and ShoppingCartItem objects for paypal payments.
|
212
|
+
|
213
|
+
Contributing
|
214
|
+
============
|
215
|
+
|
216
|
+
1. Fork it ( https://github.com/paymill/paymill-ruby/fork )
|
217
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
218
|
+
3. Setup the project (`bundle install`)
|
219
|
+
4. Setup PAYMILL's test key in your environment (`export PAYMILL_API_TEST_KEY="<YOUR_TEST_KEY>"`)
|
220
|
+
5. Run all the tests (`rspec .)` or a subset from them (`rspec ./spec/paymill/models/client_spec.rb`)
|
221
|
+
6. Commit your changes (`git commit -am 'Add some feature'`)
|
222
|
+
7. Push to the branch (`git push origin my-new-feature`)
|
223
|
+
8. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/paymill.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/https'
|
3
|
+
require "paymill/version"
|
4
|
+
require 'paymill/errors'
|
5
|
+
require 'paymill/restful/methods'
|
6
|
+
|
7
|
+
module Paymill
|
8
|
+
API_VERSION = 'v2.1'
|
9
|
+
API_BASE = 'api.paymill.com'
|
10
|
+
|
11
|
+
autoload :Address, 'paymill/models/address'
|
12
|
+
autoload :Base, 'paymill/models/base'
|
13
|
+
autoload :Checksum, 'paymill/models/checksum'
|
14
|
+
autoload :Client, 'paymill/models/client'
|
15
|
+
autoload :Fee, 'paymill/models/fee'
|
16
|
+
autoload :Invoice, 'paymill/models/invoice'
|
17
|
+
autoload :Merchant, 'paymill/models/merchant'
|
18
|
+
autoload :Offer, 'paymill/models/offer'
|
19
|
+
autoload :Payment, 'paymill/models/payment'
|
20
|
+
autoload :PaymentMethod, 'paymill/models/payment_method'
|
21
|
+
autoload :Preauthorization, 'paymill/models/preauthorization'
|
22
|
+
autoload :Refund, 'paymill/models/refund.rb'
|
23
|
+
autoload :ShoppingCartItem, 'paymill/models/shopping_cart_item'
|
24
|
+
autoload :Subscription, 'paymill/models/subscription'
|
25
|
+
autoload :SubscriptionCount, 'paymill/models/subscription_count'
|
26
|
+
autoload :Transaction, 'paymill/models/transaction'
|
27
|
+
autoload :Webhook, 'paymill/models/webhook'
|
28
|
+
|
29
|
+
def self.api_version
|
30
|
+
API_VERSION
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.api_key
|
34
|
+
@@api_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.api_key=( api_key )
|
38
|
+
@@api_key = api_key
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.request( payload )
|
42
|
+
raise AuthenticationError unless Paymill.api_key
|
43
|
+
https ||= Net::HTTP.new( API_BASE, Net::HTTP.https_default_port)
|
44
|
+
https.use_ssl = true
|
45
|
+
|
46
|
+
response = https.start do
|
47
|
+
https.request( payload )
|
48
|
+
end
|
49
|
+
|
50
|
+
raise PaymillError, response.body unless response.class.eql? Net::HTTPOK
|
51
|
+
JSON.parse( response.body )
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Address
|
3
|
+
attr_accessor :name, :street_address, :street_address_addition, :city, :state, :postal_code, :country, :phone
|
4
|
+
|
5
|
+
def initialize( arguments = {} )
|
6
|
+
arguments.each do |key, value|
|
7
|
+
raise ArgumentError.new( "parameter #{key} is not allowed" ) unless Address.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,50 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Base
|
3
|
+
extend Restful::All
|
4
|
+
extend Restful::Find
|
5
|
+
extend Restful::Create
|
6
|
+
|
7
|
+
attr_reader :id, :created_at, :updated_at, :app_id
|
8
|
+
|
9
|
+
def initialize( json )
|
10
|
+
deserialize( json )
|
11
|
+
parse_timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def self.create_with?( incoming_arguments )
|
16
|
+
return false if mandatory_arguments.select { |a| incoming_arguments.include? a }.size < mandatory_arguments.size
|
17
|
+
allowed_arguments.size == ( allowed_arguments | incoming_arguments ).size
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parses UNIX timestamps and creates Time objects.
|
21
|
+
def parse_timestamps
|
22
|
+
@created_at &&= Time.at( @created_at )
|
23
|
+
@updated_at &&= Time.at( @updated_at )
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def deserialize( json )
|
28
|
+
json.each_pair do |key, value|
|
29
|
+
case value.class.name
|
30
|
+
when 'Array'
|
31
|
+
unless key[-1].eql? 's'
|
32
|
+
instance_variable_set( "@#{key}s", value.map { |e| (e.is_a? String) ? e : objectize( key, e ) } )
|
33
|
+
else
|
34
|
+
instance_variable_set( "@#{key}", value.map { |e| (e.is_a? String) ? e : objectize( key, e ) } )
|
35
|
+
end
|
36
|
+
when 'Hash'
|
37
|
+
instance_variable_set( "@#{key}", objectize( key, value ) )
|
38
|
+
else
|
39
|
+
instance_variable_set( "@#{key}", (Integer( value ) rescue value) )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Converts the given 'hash' object into an instance of class with name stored in 'clazz' variable
|
45
|
+
def objectize( clazz, hash )
|
46
|
+
Module.const_get( "#{self.class.name.split( '::' ).first}::#{clazz.split('_').map(&:capitalize).join}" ).new( hash )
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Checksum
|
3
|
+
extend Restful::Create
|
4
|
+
|
5
|
+
attr_reader :id, :created_at, :updated_at, :app_id, :action, :checksum, :data, :type, :shipping_address
|
6
|
+
|
7
|
+
def initialize( json )
|
8
|
+
deserialize( json )
|
9
|
+
parse_timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
def self.create_with?( incoming_arguments )
|
14
|
+
return false if mandatory_arguments.select { |a| incoming_arguments.include? a }.size < mandatory_arguments.size
|
15
|
+
allowed_arguments.size == ( allowed_arguments | incoming_arguments ).size
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.allowed_arguments
|
19
|
+
[:checksum_type, :amount, :currency, :description, :return_url, :cancel_url, :items, :shipping_address, :billing_address, :fee_amount, :fee_payment, :fee_currency, :app_id]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.mandatory_arguments
|
23
|
+
[:checksum_type, :amount, :currency, :return_url, :cancel_url]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Parses UNIX timestamps and creates Time objects.
|
27
|
+
def parse_timestamps
|
28
|
+
@created_at &&= Time.at( @created_at )
|
29
|
+
@updated_at &&= Time.at( @updated_at )
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def deserialize( json )
|
34
|
+
json.each_pair do |key, value|
|
35
|
+
instance_variable_set( "@#{key}", (Integer( value ) rescue value) )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|