iyzi 0.0.1

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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +84 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/examples.md +286 -0
  13. data/iyzi.gemspec +32 -0
  14. data/lib/iyzi.rb +52 -0
  15. data/lib/iyzi/api_error.rb +7 -0
  16. data/lib/iyzi/configuration.rb +38 -0
  17. data/lib/iyzi/endpoints.rb +25 -0
  18. data/lib/iyzi/pki_builder.rb +88 -0
  19. data/lib/iyzi/pki_builders/address.rb +17 -0
  20. data/lib/iyzi/pki_builders/basket_item.rb +25 -0
  21. data/lib/iyzi/pki_builders/basket_items.rb +17 -0
  22. data/lib/iyzi/pki_builders/bin_control.rb +15 -0
  23. data/lib/iyzi/pki_builders/buyer.rb +30 -0
  24. data/lib/iyzi/pki_builders/card_storage.rb +23 -0
  25. data/lib/iyzi/pki_builders/checkout_form.rb +36 -0
  26. data/lib/iyzi/pki_builders/checkout_form_auth.rb +15 -0
  27. data/lib/iyzi/pki_builders/payment_auth.rb +36 -0
  28. data/lib/iyzi/pki_builders/payment_card.rb +23 -0
  29. data/lib/iyzi/pki_builders/store_card.rb +19 -0
  30. data/lib/iyzi/pki_builders/sub_merchant.rb +63 -0
  31. data/lib/iyzi/request.rb +88 -0
  32. data/lib/iyzi/requests/api_test.rb +9 -0
  33. data/lib/iyzi/requests/bin_control.rb +13 -0
  34. data/lib/iyzi/requests/card_storage.rb +30 -0
  35. data/lib/iyzi/requests/checkout_form.rb +13 -0
  36. data/lib/iyzi/requests/checkout_form_auth.rb +13 -0
  37. data/lib/iyzi/requests/payment_auth.rb +13 -0
  38. data/lib/iyzi/requests/sub_merchant.rb +30 -0
  39. data/lib/iyzi/resources.rb +35 -0
  40. data/lib/iyzi/utils.rb +37 -0
  41. data/lib/iyzi/version.rb +3 -0
  42. metadata +210 -0
@@ -0,0 +1,23 @@
1
+ module Iyzi
2
+ module PkiBuilders
3
+ class PaymentCard < PkiBuilder
4
+ ATTRIBUTES_ORDER = %w{
5
+ locale
6
+ conversationId
7
+ cardHolderName
8
+ cardNumber
9
+ expireYear
10
+ expireMonth
11
+ cvc
12
+ registerCard
13
+ cardAlias
14
+ cardToken
15
+ cardUserKey
16
+ }
17
+
18
+ def initialize(values = {})
19
+ super(values, ATTRIBUTES_ORDER)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Iyzi
2
+ module PkiBuilders
3
+ class StoreCard < PkiBuilder
4
+ ATTRIBUTES_ORDER = %w{
5
+ locale
6
+ conversationId
7
+ cardAlias
8
+ cardNumber
9
+ expireYear
10
+ expireMonth
11
+ cardHolderName
12
+ }
13
+
14
+ def initialize(values = {})
15
+ super(values, ATTRIBUTES_ORDER)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,63 @@
1
+ module Iyzi
2
+ module PkiBuilders
3
+ class SubMerchant < PkiBuilder
4
+ CREATE_ATTRIBUTES_ORDER = %w{
5
+ locale
6
+ conversationId
7
+ name
8
+ email
9
+ gsmNumber
10
+ address
11
+ iban
12
+ taxOffice
13
+ contactName
14
+ contactSurname
15
+ legalCompanyTitle
16
+ subMerchantExternalId
17
+ identityNumber
18
+ taxNumber
19
+ subMerchantType
20
+ }.freeze
21
+
22
+ UPDATE_ATTRIBUTE_ORDER = %w{
23
+ locale
24
+ conversationId
25
+ name
26
+ email
27
+ gsmNumber
28
+ address
29
+ iban
30
+ taxOffice
31
+ contactName
32
+ contactSurname
33
+ legalCompanyTitle
34
+ subMerchantKey
35
+ identityNumber
36
+ taxNumber
37
+ }
38
+
39
+ RETREIVE_ATTRIBUTE_ORDER = %w{
40
+ locale
41
+ conversationId
42
+ subMerchantExternalId
43
+ }
44
+
45
+ def initialize(type, values = {})
46
+ super(values, order_for(type))
47
+ end
48
+
49
+ def order_for(type)
50
+ case type
51
+ when :create
52
+ CREATE_ATTRIBUTES_ORDER
53
+ when :update
54
+ UPDATE_ATTRIBUTE_ORDER
55
+ when :retreive
56
+ RETREIVE_ATTRIBUTE_ORDER
57
+ else
58
+ raise "no attribute order for #{type}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,88 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Iyzi
5
+ class Request
6
+ AUTHORIZATION_HEADER_NAME = 'Authorization'.freeze
7
+ RANDOM_HEADER_NAME = 'x-iyzi-rnd'.freeze
8
+ AUTHORIZATION_HEADER_STRING = 'IYZWS %s:%s'.freeze
9
+ DEFAULT_LOCALE = 'tr'.freeze
10
+
11
+ attr_accessor :config, :method, :path, :conversation_id, :locale, :random_string, :pki, :options
12
+
13
+ def initialize(method, path, options = {})
14
+ @method = method
15
+ @path = path
16
+ # use default config which comes from initial setup
17
+ # you can also send custom config object which you'd like to use
18
+ @config = options.delete(:config) || Iyzi.configuration
19
+ @options = options
20
+ @locale = options[:locale] || DEFAULT_LOCALE
21
+ @conversation_id = options[:conversation_id]
22
+ @pki = to_pki
23
+ @random_string = secure_random_string
24
+ # config must have all required params
25
+ config.validate if has_pki?
26
+ end
27
+
28
+ def iyzi_options
29
+ Utils.hash_to_properties(options)
30
+ end
31
+
32
+ def connection
33
+ @conn ||= Faraday.new(url: config.base_url) do |faraday|
34
+ faraday.request :json
35
+ faraday.response :logger # log requests to STDOUT
36
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
37
+ faraday.response :json, content_type: /\bjson$/
38
+ end
39
+ end
40
+
41
+ def call
42
+ connection.send(method) do |req|
43
+ req.url path
44
+ req.headers['Accept'] = 'application/json'
45
+ req.headers['Content-Type'] = 'application/json'
46
+ req.headers.merge!(auth_headers) if has_pki?
47
+ req.body = iyzi_options
48
+ end
49
+ end
50
+
51
+ def response
52
+ @response ||= Utils.properties_to_hash(call.body)
53
+ block_given? ? yield(@response) : @response
54
+ end
55
+
56
+ def auth_headers
57
+ {
58
+ AUTHORIZATION_HEADER_NAME => auth_header_string,
59
+ RANDOM_HEADER_NAME => random_string
60
+ }
61
+ end
62
+
63
+ def auth_header_string
64
+ format(AUTHORIZATION_HEADER_STRING, config.api_key, request_hash_digest)
65
+ end
66
+
67
+ def request_hash_digest
68
+ Digest::SHA1.base64digest(params_will_be_hashed)
69
+ end
70
+
71
+ def params_will_be_hashed
72
+ config.api_key + random_string + config.secret + pki
73
+ end
74
+
75
+ def secure_random_string
76
+ SecureRandom.urlsafe_base64(6, false)
77
+ end
78
+
79
+ def has_pki?
80
+ !pki.nil? && !pki.to_s.empty?
81
+ end
82
+
83
+ # implement if needed
84
+ def to_pki
85
+ ''
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ module Iyzi
2
+ module Requests
3
+ class ApiTest < Request
4
+ def initialize(options = {})
5
+ super(Endpoints::HTTP_GET, Endpoints::API_TEST, options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Iyzi
2
+ module Requests
3
+ class BinControl < Request
4
+ def initialize(options = {})
5
+ super(Endpoints::HTTP_POST, Endpoints::BIN_CONTROL, options)
6
+ end
7
+
8
+ def to_pki
9
+ PkiBuilders::BinControl.new(iyzi_options).request_string
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module Iyzi
2
+ module Requests
3
+ class CardStorage < Request
4
+ attr_accessor :type
5
+
6
+ class << self
7
+ def add(options)
8
+ new(:add, Endpoints::HTTP_POST, Endpoints::CARD_STORAGE_ADD, options)
9
+ end
10
+
11
+ def delete(options)
12
+ new(:delete, Endpoints::HTTP_DELETE, Endpoints::CARD_STORAGE_DELETE, options)
13
+ end
14
+
15
+ def list(options)
16
+ new(:list, Endpoints::HTTP_POST, Endpoints::CARD_STORAGE_LIST, options)
17
+ end
18
+ end
19
+
20
+ def initialize(type, method, path, options = {})
21
+ @type = type
22
+ super(method, path, options)
23
+ end
24
+
25
+ def to_pki
26
+ PkiBuilders::CardStorage.new(iyzi_options).request_string
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Iyzi
2
+ module Requests
3
+ class CheckoutForm < Request
4
+ def initialize(options = {})
5
+ super(Endpoints::HTTP_POST, Endpoints::CHECKOUT_FORM_INITIALIZE, options)
6
+ end
7
+
8
+ def to_pki
9
+ PkiBuilders::CheckoutForm.new(iyzi_options).request_string
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Iyzi
2
+ module Requests
3
+ class CheckoutFormAuth < Request
4
+ def initialize(options = {})
5
+ super(Endpoints::HTTP_POST, Endpoints::CHECKOUT_FORM_AUTH, options)
6
+ end
7
+
8
+ def to_pki
9
+ PkiBuilders::CheckoutFormAuth.new(iyzi_options).request_string
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Iyzi
2
+ module Requests
3
+ class PaymentAuth < Request
4
+ def initialize(options = {})
5
+ super(Endpoints::HTTP_POST, Endpoints::PAYMENT_AUTH_CREATE, options)
6
+ end
7
+
8
+ def to_pki
9
+ PkiBuilders::PaymentAuth.new(iyzi_options).request_string
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module Iyzi
2
+ module Requests
3
+ class SubMerchant < Request
4
+ attr_accessor :type
5
+
6
+ class << self
7
+ def create(options)
8
+ new(:create, Endpoints::HTTP_POST, Endpoints::SUB_MERCHANT_CREATE, options)
9
+ end
10
+
11
+ def update(options)
12
+ new(:update, Endpoints::HTTP_PUT, Endpoints::SUB_MERCHANT_UPDATE, options)
13
+ end
14
+
15
+ def retreive(options)
16
+ new(:retreive, Endpoints::HTTP_POST, Endpoints::SUB_MERCHANT_DETAIL, options)
17
+ end
18
+ end
19
+
20
+ def initialize(type, method, path, options = {})
21
+ @type = type
22
+ super(method, path, options)
23
+ end
24
+
25
+ def to_pki
26
+ PkiBuilders::SubMerchant.new(type, iyzi_options).request_string
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ module Iyzi
2
+ module Resources
3
+ def api_test
4
+ Requests::ApiTest.new.response
5
+ end
6
+
7
+ def checkout_form(options, &block)
8
+ Requests::CheckoutForm.new(options).response(&block)
9
+ end
10
+
11
+ def checkout_form_auth(options, &block)
12
+ Requests::CheckoutFormAuth.new(options).response(&block)
13
+ end
14
+
15
+ def payment_auth(options, &block)
16
+ Requests::PaymentAuth.new(options).response(&block)
17
+ end
18
+
19
+ def register_card(options, &block)
20
+ Requests::CardStorage.add(options).response(&block)
21
+ end
22
+
23
+ def list_cards(options, &block)
24
+ Requests::CardStorage.list(options).response(&block)
25
+ end
26
+
27
+ def delete_card(options, &block)
28
+ Requests::CardStorage.delete(options).response(&block)
29
+ end
30
+
31
+ def bin_control(options, &block)
32
+ Requests::BinControl.new(options).response(&block)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ module Iyzi
2
+ class Utils
3
+ class << self
4
+ def hash_to_properties(hash)
5
+ newprops = {}
6
+ hash.each_pair { |k, v| newprops[k.to_s.camelize(:lower)] = convert_to_prop(v) }
7
+ newprops
8
+ end
9
+
10
+ def properties_to_hash(props)
11
+ hash = HashWithIndifferentAccess.new
12
+ props.each_pair { |k, v| hash[k.underscore] = convert_to_hash(v) }
13
+ hash
14
+ end
15
+
16
+ def convert_to_prop(v)
17
+ if v.is_a?(Hash)
18
+ hash_to_properties(v)
19
+ elsif v.is_a?(Array)
20
+ v.collect { |item| hash_to_properties(item) }
21
+ else
22
+ v
23
+ end
24
+ end
25
+
26
+ def convert_to_hash(v)
27
+ if v.is_a?(Hash)
28
+ properties_to_hash(v)
29
+ elsif v.is_a?(Array)
30
+ v.collect { |item| properties_to_hash(item) }
31
+ else
32
+ v
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Iyzi
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iyzi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Demirhan Aydin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: awesome_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description: Iyzico ruby client for api v1.0
140
+ email:
141
+ - demirhanaydin@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".ruby-version"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/setup
156
+ - examples.md
157
+ - iyzi.gemspec
158
+ - lib/iyzi.rb
159
+ - lib/iyzi/api_error.rb
160
+ - lib/iyzi/configuration.rb
161
+ - lib/iyzi/endpoints.rb
162
+ - lib/iyzi/pki_builder.rb
163
+ - lib/iyzi/pki_builders/address.rb
164
+ - lib/iyzi/pki_builders/basket_item.rb
165
+ - lib/iyzi/pki_builders/basket_items.rb
166
+ - lib/iyzi/pki_builders/bin_control.rb
167
+ - lib/iyzi/pki_builders/buyer.rb
168
+ - lib/iyzi/pki_builders/card_storage.rb
169
+ - lib/iyzi/pki_builders/checkout_form.rb
170
+ - lib/iyzi/pki_builders/checkout_form_auth.rb
171
+ - lib/iyzi/pki_builders/payment_auth.rb
172
+ - lib/iyzi/pki_builders/payment_card.rb
173
+ - lib/iyzi/pki_builders/store_card.rb
174
+ - lib/iyzi/pki_builders/sub_merchant.rb
175
+ - lib/iyzi/request.rb
176
+ - lib/iyzi/requests/api_test.rb
177
+ - lib/iyzi/requests/bin_control.rb
178
+ - lib/iyzi/requests/card_storage.rb
179
+ - lib/iyzi/requests/checkout_form.rb
180
+ - lib/iyzi/requests/checkout_form_auth.rb
181
+ - lib/iyzi/requests/payment_auth.rb
182
+ - lib/iyzi/requests/sub_merchant.rb
183
+ - lib/iyzi/resources.rb
184
+ - lib/iyzi/utils.rb
185
+ - lib/iyzi/version.rb
186
+ homepage: https://github.com/parasutcom/iyzi
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.4.5.1
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Iyzico ruby client
210
+ test_files: []