iyzi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/examples.md +286 -0
- data/iyzi.gemspec +32 -0
- data/lib/iyzi.rb +52 -0
- data/lib/iyzi/api_error.rb +7 -0
- data/lib/iyzi/configuration.rb +38 -0
- data/lib/iyzi/endpoints.rb +25 -0
- data/lib/iyzi/pki_builder.rb +88 -0
- data/lib/iyzi/pki_builders/address.rb +17 -0
- data/lib/iyzi/pki_builders/basket_item.rb +25 -0
- data/lib/iyzi/pki_builders/basket_items.rb +17 -0
- data/lib/iyzi/pki_builders/bin_control.rb +15 -0
- data/lib/iyzi/pki_builders/buyer.rb +30 -0
- data/lib/iyzi/pki_builders/card_storage.rb +23 -0
- data/lib/iyzi/pki_builders/checkout_form.rb +36 -0
- data/lib/iyzi/pki_builders/checkout_form_auth.rb +15 -0
- data/lib/iyzi/pki_builders/payment_auth.rb +36 -0
- data/lib/iyzi/pki_builders/payment_card.rb +23 -0
- data/lib/iyzi/pki_builders/store_card.rb +19 -0
- data/lib/iyzi/pki_builders/sub_merchant.rb +63 -0
- data/lib/iyzi/request.rb +88 -0
- data/lib/iyzi/requests/api_test.rb +9 -0
- data/lib/iyzi/requests/bin_control.rb +13 -0
- data/lib/iyzi/requests/card_storage.rb +30 -0
- data/lib/iyzi/requests/checkout_form.rb +13 -0
- data/lib/iyzi/requests/checkout_form_auth.rb +13 -0
- data/lib/iyzi/requests/payment_auth.rb +13 -0
- data/lib/iyzi/requests/sub_merchant.rb +30 -0
- data/lib/iyzi/resources.rb +35 -0
- data/lib/iyzi/utils.rb +37 -0
- data/lib/iyzi/version.rb +3 -0
- metadata +210 -0
data/iyzi.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iyzi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iyzi"
|
8
|
+
spec.version = Iyzi::VERSION
|
9
|
+
spec.authors = ["Demirhan Aydin"]
|
10
|
+
spec.email = ["demirhanaydin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Iyzico ruby client}
|
13
|
+
spec.description = %q{Iyzico ruby client for api v1.0}
|
14
|
+
spec.homepage = "https://github.com/parasutcom/iyzi"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "faraday", '~> 0.9.2'
|
23
|
+
spec.add_dependency "faraday_middleware", '~> 0.10.0'
|
24
|
+
spec.add_dependency "activesupport", '~> 4.2'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "awesome_print", '~> 1.6'
|
30
|
+
spec.add_development_dependency "webmock", "~> 1.2"
|
31
|
+
spec.add_development_dependency "vcr", "~> 3.0"
|
32
|
+
end
|
data/lib/iyzi.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'iyzi/version'
|
2
|
+
require 'iyzi/configuration'
|
3
|
+
require 'iyzi/resources'
|
4
|
+
require 'iyzi/endpoints'
|
5
|
+
require 'iyzi/api_error'
|
6
|
+
require 'iyzi/utils'
|
7
|
+
|
8
|
+
# PKI Builders
|
9
|
+
require 'iyzi/pki_builder'
|
10
|
+
require 'iyzi/pki_builders/basket_item'
|
11
|
+
require 'iyzi/pki_builders/basket_items'
|
12
|
+
require 'iyzi/pki_builders/address'
|
13
|
+
require 'iyzi/pki_builders/buyer'
|
14
|
+
require 'iyzi/pki_builders/checkout_form'
|
15
|
+
require 'iyzi/pki_builders/checkout_form_auth'
|
16
|
+
require 'iyzi/pki_builders/sub_merchant'
|
17
|
+
require 'iyzi/pki_builders/card_storage'
|
18
|
+
require 'iyzi/pki_builders/payment_card'
|
19
|
+
require 'iyzi/pki_builders/store_card'
|
20
|
+
require 'iyzi/pki_builders/payment_auth'
|
21
|
+
require 'iyzi/pki_builders/bin_control'
|
22
|
+
|
23
|
+
# Requests
|
24
|
+
require 'iyzi/request'
|
25
|
+
require 'iyzi/requests/api_test'
|
26
|
+
require 'iyzi/requests/checkout_form'
|
27
|
+
require 'iyzi/requests/checkout_form_auth'
|
28
|
+
require 'iyzi/requests/sub_merchant'
|
29
|
+
require 'iyzi/requests/card_storage'
|
30
|
+
require 'iyzi/requests/payment_auth'
|
31
|
+
require 'iyzi/requests/bin_control'
|
32
|
+
|
33
|
+
# Misc
|
34
|
+
require 'active_support/all'
|
35
|
+
|
36
|
+
module Iyzi
|
37
|
+
extend Resources
|
38
|
+
|
39
|
+
class << self
|
40
|
+
def configuration
|
41
|
+
@configuration ||= Configuration.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset
|
45
|
+
@configuration = Configuration.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def configure
|
49
|
+
yield(configuration)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Iyzi
|
2
|
+
class Configuration
|
3
|
+
BASE_URL = 'https://api.iyzipay.com/'.freeze
|
4
|
+
REQUIRED_CONFIG = %i(base_url api_key secret)
|
5
|
+
attr_accessor :base_url, :api_key, :secret
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@base_url = options[:base_url] || BASE_URL
|
9
|
+
@api_key = options[:api_key]
|
10
|
+
@secret = options[:secret]
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
!missing_configs.present?
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate
|
18
|
+
return if valid?
|
19
|
+
fail "Missing configuration keys: #{missing_configs.collect(&:to_s).join(', ')}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def missing_configs
|
23
|
+
REQUIRED_CONFIG - defined_params.keys.collect(&:to_sym)
|
24
|
+
end
|
25
|
+
|
26
|
+
def defined_params
|
27
|
+
to_h.select { |k, v| v.present? }
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
{
|
32
|
+
base_url: base_url,
|
33
|
+
api_key: api_key,
|
34
|
+
secret: secret
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module Endpoints
|
3
|
+
API_TEST = '/payment/test'.freeze
|
4
|
+
BIN_CONTROL = '/payment/bin/check'.freeze
|
5
|
+
CHECKOUT_FORM_INITIALIZE = '/payment/iyzipos/checkoutform/initialize/ecom'.freeze
|
6
|
+
CHECKOUT_FORM_AUTH = '/payment/iyzipos/checkoutform/auth/ecom/detail'.freeze
|
7
|
+
SUB_MERCHANT_CREATE = '/onboarding/submerchant'.freeze
|
8
|
+
SUB_MERCHANT_UPDATE = '/onboarding/submerchant'.freeze
|
9
|
+
SUB_MERCHANT_DETAIL = '/onboarding/submerchant/detail'.freeze
|
10
|
+
|
11
|
+
# CARD STORAGE
|
12
|
+
CARD_STORAGE_ADD = '/cardstorage/card'.freeze
|
13
|
+
CARD_STORAGE_DELETE = '/cardstorage/card'.freeze
|
14
|
+
CARD_STORAGE_LIST = '/cardstorage/cards'.freeze
|
15
|
+
|
16
|
+
# PAYMENT AUTH
|
17
|
+
PAYMENT_AUTH_CREATE = '/payment/iyzipos/auth/ecom'.freeze
|
18
|
+
|
19
|
+
# HTTP VERBS
|
20
|
+
HTTP_POST = 'post'.freeze
|
21
|
+
HTTP_GET = 'get'.freeze
|
22
|
+
HTTP_PUT = 'put'.freeze
|
23
|
+
HTTP_DELETE = 'delete'.freeze
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Iyzi
|
2
|
+
class PkiBuilder
|
3
|
+
DEFAULT_ADD_METHOD = 'add'
|
4
|
+
|
5
|
+
attr_accessor :params, :ordered_keys
|
6
|
+
|
7
|
+
def initialize(values = {}, ordered_keys = nil, type_cast = {})
|
8
|
+
@params = {}
|
9
|
+
assign_params(values, type_cast)
|
10
|
+
@ordered_keys = ordered_keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def request_string
|
14
|
+
str = prepare_request_string
|
15
|
+
"[#{str}]" unless str.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def prepare_request_string
|
19
|
+
ordered_params.join(',')
|
20
|
+
end
|
21
|
+
|
22
|
+
def ordered_params
|
23
|
+
orderer.map do |key|
|
24
|
+
convert_str(key, params[key]) if params[key].present?
|
25
|
+
end.reject(&:nil?)
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_price(key, value)
|
29
|
+
add(key, value.to_f.round(2)) if value.to_f != 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_array(key, value)
|
33
|
+
add(key, "[#{value.join(', ')}]") if value.present?
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_date(key, value)
|
37
|
+
add(key, parse_date(value).strftime('%Y-%m-%d %H:%M:%S')) if value.present?
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_buyer(key, value)
|
41
|
+
add(key, PkiBuilders::Buyer.new(value).request_string)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_address(key, value)
|
45
|
+
add(key, PkiBuilders::Address.new(value).request_string)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_basket_items(key, value)
|
49
|
+
add_array(key, PkiBuilders::BasketItems.new(value).request_array)
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_payment_card(key, value)
|
53
|
+
add(key, PkiBuilders::PaymentCard.new(value).request_string)
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_store_card(key, value)
|
57
|
+
add(key, PkiBuilders::StoreCard.new(value).request_string)
|
58
|
+
end
|
59
|
+
|
60
|
+
def add(key, value)
|
61
|
+
params[key] = value.to_s unless value.to_s.empty?
|
62
|
+
end
|
63
|
+
|
64
|
+
def convert_str(key, value)
|
65
|
+
"#{key}=#{value}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_date(value)
|
69
|
+
value.is_a?(String) ? DateTime.parse(value) : value
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def orderer
|
75
|
+
ordered_keys || params.keys
|
76
|
+
end
|
77
|
+
|
78
|
+
def assign_params(values, type_cast)
|
79
|
+
values.each_pair do |key, value|
|
80
|
+
send(adder(type_cast[key.to_sym]), key, value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def adder(add_method)
|
85
|
+
add_method || DEFAULT_ADD_METHOD
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module PkiBuilders
|
3
|
+
class BasketItem < PkiBuilder
|
4
|
+
ATTRIBUTES_ORDER = %w{
|
5
|
+
id
|
6
|
+
price
|
7
|
+
name
|
8
|
+
category1
|
9
|
+
category2
|
10
|
+
itemType
|
11
|
+
subMerchantKey
|
12
|
+
subMerchantPrice
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
TYPE_CAST = {
|
16
|
+
price: 'add_price',
|
17
|
+
subMerchantPrice: 'add_price'
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
def initialize(values = {})
|
21
|
+
super(values, ATTRIBUTES_ORDER, TYPE_CAST)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module PkiBuilders
|
3
|
+
class BasketItems
|
4
|
+
attr_reader :items
|
5
|
+
|
6
|
+
def initialize(basket_items = [])
|
7
|
+
@items = basket_items
|
8
|
+
end
|
9
|
+
|
10
|
+
def request_array
|
11
|
+
(items || []).collect do |item|
|
12
|
+
BasketItem.new(item).request_string
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module PkiBuilders
|
3
|
+
class Buyer < PkiBuilder
|
4
|
+
ATTRIBUTES_ORDER = %w{
|
5
|
+
id
|
6
|
+
name
|
7
|
+
surname
|
8
|
+
identityNumber
|
9
|
+
email
|
10
|
+
gsmNumber
|
11
|
+
registrationDate
|
12
|
+
lastLoginDate
|
13
|
+
registrationAddress
|
14
|
+
city
|
15
|
+
country
|
16
|
+
zipCode
|
17
|
+
ip
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
TYPE_CAST = {
|
21
|
+
registrationDate: 'add_date',
|
22
|
+
lastLoginDate: 'add_date'
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
def initialize(values = {})
|
26
|
+
super(values, ATTRIBUTES_ORDER, TYPE_CAST)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module PkiBuilders
|
3
|
+
class CardStorage < PkiBuilder
|
4
|
+
ATTRIBUTES_ORDER = %w{
|
5
|
+
locale
|
6
|
+
conversationId
|
7
|
+
externalId
|
8
|
+
email
|
9
|
+
cardUserKey
|
10
|
+
cardToken
|
11
|
+
card
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
TYPE_CAST = {
|
15
|
+
card: 'add_store_card'
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
def initialize(values = {})
|
19
|
+
super(values, ATTRIBUTES_ORDER, TYPE_CAST)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module PkiBuilders
|
3
|
+
class CheckoutForm < PkiBuilder
|
4
|
+
ATTRIBUTES_ORDER = %w{
|
5
|
+
locale
|
6
|
+
conversationId
|
7
|
+
price
|
8
|
+
basketId
|
9
|
+
paymentGroup
|
10
|
+
buyer
|
11
|
+
shippingAddress
|
12
|
+
billingAddress
|
13
|
+
basketItems
|
14
|
+
callbackUrl
|
15
|
+
paymentSource
|
16
|
+
posOrderId
|
17
|
+
paidPrice
|
18
|
+
forceThreeDS
|
19
|
+
cardUserKey
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
TYPE_CAST = {
|
23
|
+
price: 'add_price',
|
24
|
+
buyer: 'add_buyer',
|
25
|
+
shippingAddress: 'add_address',
|
26
|
+
billingAddress: 'add_address',
|
27
|
+
basketItems: 'add_basket_items',
|
28
|
+
paidPrice: 'add_price'
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
def initialize(values = {})
|
32
|
+
super(values, ATTRIBUTES_ORDER, TYPE_CAST)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Iyzi
|
2
|
+
module PkiBuilders
|
3
|
+
class PaymentAuth < PkiBuilder
|
4
|
+
ATTRIBUTES_ORDER = %w{
|
5
|
+
locale
|
6
|
+
conversationId
|
7
|
+
price
|
8
|
+
paidPrice
|
9
|
+
installment
|
10
|
+
paymentChannel
|
11
|
+
basketId
|
12
|
+
paymentGroup
|
13
|
+
paymentCard
|
14
|
+
buyer
|
15
|
+
shippingAddress
|
16
|
+
billingAddress
|
17
|
+
basketItems
|
18
|
+
paymentSource
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
TYPE_CAST = {
|
22
|
+
price: 'add_price',
|
23
|
+
paidPrice: 'add_price',
|
24
|
+
paymentCard: 'add_payment_card',
|
25
|
+
buyer: 'add_buyer',
|
26
|
+
shippingAddress: 'add_address',
|
27
|
+
billingAddress: 'add_address',
|
28
|
+
basketItems: 'add_basket_items'
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
def initialize(values = {})
|
32
|
+
super(values, ATTRIBUTES_ORDER, TYPE_CAST)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|