iyzipay 1.0.29

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 (84) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +14 -0
  7. data/Gemfile +8 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +3 -0
  10. data/Rakefile +5 -0
  11. data/VERSION +1 -0
  12. data/contributors +2 -0
  13. data/iyzipay.gemspec +24 -0
  14. data/lib/Iyzipay.rb +16 -0
  15. data/lib/iyzipay/http_client.rb +19 -0
  16. data/lib/iyzipay/iyzipay_resource.rb +59 -0
  17. data/lib/iyzipay/model.rb +43 -0
  18. data/lib/iyzipay/model/address.rb +17 -0
  19. data/lib/iyzipay/model/approval.rb +17 -0
  20. data/lib/iyzipay/model/basic_bkm.rb +17 -0
  21. data/lib/iyzipay/model/basic_bkm_initialize.rb +24 -0
  22. data/lib/iyzipay/model/basic_payment.rb +26 -0
  23. data/lib/iyzipay/model/basic_payment_post_auth.rb +19 -0
  24. data/lib/iyzipay/model/basic_payment_pre_auth.rb +26 -0
  25. data/lib/iyzipay/model/basic_threeds_initialize.rb +26 -0
  26. data/lib/iyzipay/model/basic_threeds_initialize_pre_auth.rb +26 -0
  27. data/lib/iyzipay/model/basic_threeds_payment.rb +18 -0
  28. data/lib/iyzipay/model/basket.rb +26 -0
  29. data/lib/iyzipay/model/basket_item_type.rb +8 -0
  30. data/lib/iyzipay/model/bin_number.rb +17 -0
  31. data/lib/iyzipay/model/bkm.rb +17 -0
  32. data/lib/iyzipay/model/bkm_initialize.rb +24 -0
  33. data/lib/iyzipay/model/bounced_bank_transfer_list.rb +17 -0
  34. data/lib/iyzipay/model/buyer.rb +25 -0
  35. data/lib/iyzipay/model/cancel.rb +18 -0
  36. data/lib/iyzipay/model/checkout_form.rb +17 -0
  37. data/lib/iyzipay/model/checkout_form_initialize.rb +29 -0
  38. data/lib/iyzipay/model/checkout_form_initialize_pre_auth.rb +29 -0
  39. data/lib/iyzipay/model/cross_booking_from_sub_merchant.rb +19 -0
  40. data/lib/iyzipay/model/cross_booking_to_sub_merchant.rb +19 -0
  41. data/lib/iyzipay/model/disapproval.rb +17 -0
  42. data/lib/iyzipay/model/installment_details.rb +19 -0
  43. data/lib/iyzipay/model/installment_info.rb +18 -0
  44. data/lib/iyzipay/model/installment_prices.rb +19 -0
  45. data/lib/iyzipay/model/payment.rb +28 -0
  46. data/lib/iyzipay/model/payment_card.rb +22 -0
  47. data/lib/iyzipay/model/payment_channel.rb +14 -0
  48. data/lib/iyzipay/model/payment_group.rb +9 -0
  49. data/lib/iyzipay/model/payment_post_auth.rb +19 -0
  50. data/lib/iyzipay/model/payment_pre_auth.rb +44 -0
  51. data/lib/iyzipay/model/payout_completed_transaction_list.rb +17 -0
  52. data/lib/iyzipay/model/refund.rb +19 -0
  53. data/lib/iyzipay/model/refund_charged_from_merchant.rb +19 -0
  54. data/lib/iyzipay/model/sub_merchant.rb +68 -0
  55. data/lib/iyzipay/model/sub_merchant_type.rb +9 -0
  56. data/lib/iyzipay/model/threeds_initialize.rb +28 -0
  57. data/lib/iyzipay/model/threeds_initialize_pre_auth.rb +31 -0
  58. data/lib/iyzipay/model/threeds_payment.rb +34 -0
  59. data/lib/iyzipay/options.rb +7 -0
  60. data/lib/iyzipay/pki_builder.rb +101 -0
  61. data/lib/iyzipay/version.rb +3 -0
  62. data/spec/approval_spec.rb +45 -0
  63. data/spec/basic_bkm_spec.rb +261 -0
  64. data/spec/basic_payment_post_auth_spec.rb +32 -0
  65. data/spec/basic_payment_pre_auth_spec.rb +71 -0
  66. data/spec/basic_payment_spec.rb +71 -0
  67. data/spec/basic_threeds_pre_auth_spec.rb +85 -0
  68. data/spec/basic_threeds_spec.rb +101 -0
  69. data/spec/bin_number_spec.rb +30 -0
  70. data/spec/bkm_spec.rb +111 -0
  71. data/spec/cancel_spec.rb +31 -0
  72. data/spec/checkout_form_pre_auth_spec.rb +92 -0
  73. data/spec/checkout_form_spec.rb +107 -0
  74. data/spec/cross_booking_spec.rb +49 -0
  75. data/spec/installment_spec.rb +31 -0
  76. data/spec/payment_post_auth_spec.rb +32 -0
  77. data/spec/payment_pre_auth_spec.rb +117 -0
  78. data/spec/payment_spec.rb +101 -0
  79. data/spec/refund_spec.rb +49 -0
  80. data/spec/retrieve_transactions_spec.rb +45 -0
  81. data/spec/spec_helper.rb +80 -0
  82. data/spec/sub_merchant_spec.rb +174 -0
  83. data/spec/threeds_pre_auth_spec.rb +139 -0
  84. metadata +185 -0
@@ -0,0 +1,22 @@
1
+ module Iyzipay
2
+ module Model
3
+ class PaymentCard
4
+ def self.to_pki_string(request)
5
+ unless request.nil?
6
+ PkiBuilder.new.
7
+ append(:cardHolderName, request[:cardHolderName]).
8
+ append(:cardNumber, request[:cardNumber]).
9
+ append(:expireYear, request[:expireYear]).
10
+ append(:expireMonth, request[:expireMonth]).
11
+ append(:cvc, request[:cvc]).
12
+ append(:registerCard, request[:registerCard]).
13
+ append(:cardAlias, request[:cardAlias]).
14
+ append(:cardToken, request[:cardToken]).
15
+ append(:cardUserKey, request[:cardUserKey]).
16
+ get_request_string
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,14 @@
1
+ module Iyzipay
2
+ module Model
3
+ module PaymentChannel
4
+ MOBILE = 'MOBILE'
5
+ WEB = 'WEB'
6
+ MOBILE_WEB = 'MOBILE_WEB'
7
+ MOBILE_IOS = 'MOBILE_IOS'
8
+ MOBILE_ANDROID = 'MOBILE_ANDROID'
9
+ MOBILE_WINDOWS = 'MOBILE_WINDOWS'
10
+ MOBILE_TABLET = 'MOBILE_TABLET'
11
+ MOBILE_PHONE = 'MOBILE_PHONE'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Iyzipay
2
+ module Model
3
+ module PaymentGroup
4
+ PRODUCT = 'PRODUCT'
5
+ LISTING = 'LISTING'
6
+ SUBSCRIPTION = 'SUBSCRIPTION'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Iyzipay
2
+ module Model
3
+ class PaymentPostAuth < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/postauth", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def to_pki_string(request)
11
+ PkiBuilder.new.append_super(super).
12
+ append(:paymentId, request[:paymentId]).
13
+ append(:ip, request[:ip]).
14
+ append_price(:paidPrice, request[:paidPrice]).
15
+ get_request_string
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ module Iyzipay
2
+ module Model
3
+ class PaymentPreAuth < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string_create(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/preauth/ecom", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def retrieve(request = {}, options)
11
+ pki_string = to_pki_string_retrieve(request)
12
+ HttpClient.post("#{options.base_url}/payment/detail", get_http_header(pki_string, options), request.to_json)
13
+ end
14
+
15
+ def to_pki_string_create(request)
16
+ PkiBuilder.new.
17
+ append(:locale, request[:locale]).
18
+ append(:conversationId, request[:conversationId]).
19
+ append_price(:price, request[:price]).
20
+ append_price(:paidPrice, request[:paidPrice]).
21
+ append(:installment, request[:installment]).
22
+ append(:paymentChannel, request[:paymentChannel]).
23
+ append(:basketId, request[:basketId]).
24
+ append(:paymentGroup, request[:paymentGroup]).
25
+ append(:paymentCard, PaymentCard.to_pki_string(request[:paymentCard])).
26
+ append(:buyer, Buyer.to_pki_string(request[:buyer])).
27
+ append(:shippingAddress, Address.to_pki_string(request[:shippingAddress])).
28
+ append(:billingAddress, Address.to_pki_string(request[:billingAddress])).
29
+ append_array(:basketItems, Basket.to_pki_string(request[:basketItems])).
30
+ append(:paymentSource, request[:paymentSource]).
31
+ get_request_string
32
+ end
33
+
34
+ def to_pki_string_retrieve(request)
35
+ PkiBuilder.new.
36
+ append(:locale, request[:locale]).
37
+ append(:conversationId, request[:conversationId]).
38
+ append(:paymentId, request[:paymentId]).
39
+ append(:paymentConversationId, request[:paymentConversationId]).
40
+ get_request_string
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ module Iyzipay
2
+ module Model
3
+ class PayoutCompletedTransactionList < IyzipayResource
4
+
5
+ def retrieve(request = {}, options)
6
+ pki_string = to_pki_string(request)
7
+ HttpClient.post("#{options.base_url}/reporting/settlement/payoutcompleted", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def to_pki_string(request)
11
+ PkiBuilder.new.append_super(super).
12
+ append(:date, request[:date]).
13
+ get_request_string
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Iyzipay
2
+ module Model
3
+ class Refund < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/refund", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def to_pki_string(request)
11
+ PkiBuilder.new.append_super(super).
12
+ append(:paymentTransactionId, request[:paymentTransactionId]).
13
+ append_price(:price, request[:price]).
14
+ append(:ip, request[:ip]).
15
+ get_request_string
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Iyzipay
2
+ module Model
3
+ class RefundChargedFromMerchant < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/refund/merchant/charge", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def to_pki_string(request)
11
+ PkiBuilder.new.append_super(super).
12
+ append(:paymentTransactionId, request[:paymentTransactionId]).
13
+ append_price(:price, request[:price]).
14
+ append(:ip, request[:ip]).
15
+ get_request_string
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module Iyzipay
2
+ module Model
3
+ class SubMerchant < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string_create(request)
7
+ HttpClient.post("#{options.base_url}/onboarding/submerchant", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def update(request = {}, options)
11
+ pki_string = to_pki_string_update(request)
12
+ HttpClient.put("#{options.base_url}/onboarding/submerchant", get_http_header(pki_string, options), request.to_json)
13
+ end
14
+
15
+ def retrieve(request = {}, options)
16
+ pki_string = to_pki_string_retrieve(request)
17
+ HttpClient.post("#{options.base_url}/onboarding/submerchant/detail", get_http_header(pki_string, options), request.to_json)
18
+ end
19
+
20
+ def to_pki_string_create(request)
21
+ PkiBuilder.new.
22
+ append(:locale, request[:locale]).
23
+ append(:conversationId, request[:conversationId]).
24
+ append(:name, request[:name]).
25
+ append(:email, request[:email]).
26
+ append(:gsmNumber, request[:gsmNumber]).
27
+ append(:address, request[:address]).
28
+ append(:iban, request[:iban]).
29
+ append(:taxOffice, request[:taxOffice]).
30
+ append(:contactName, request[:contactName]).
31
+ append(:contactSurname, request[:contactSurname]).
32
+ append(:legalCompanyTitle, request[:legalCompanyTitle]).
33
+ append(:subMerchantExternalId, request[:subMerchantExternalId]).
34
+ append(:identityNumber, request[:identityNumber]).
35
+ append(:taxNumber, request[:taxNumber]).
36
+ append(:subMerchantType, request[:subMerchantType]).
37
+ get_request_string
38
+ end
39
+
40
+ def to_pki_string_update(request)
41
+ PkiBuilder.new.
42
+ append(:locale, request[:locale]).
43
+ append(:conversationId, request[:conversationId]).
44
+ append(:name, request[:name]).
45
+ append(:email, request[:email]).
46
+ append(:gsmNumber, request[:gsmNumber]).
47
+ append(:address, request[:address]).
48
+ append(:iban, request[:iban]).
49
+ append(:taxOffice, request[:taxOffice]).
50
+ append(:contactName, request[:contactName]).
51
+ append(:contactSurname, request[:contactSurname]).
52
+ append(:legalCompanyTitle, request[:legalCompanyTitle]).
53
+ append(:subMerchantKey, request[:subMerchantKey]).
54
+ append(:identityNumber, request[:identityNumber]).
55
+ append(:taxNumber, request[:taxNumber]).
56
+ get_request_string
57
+ end
58
+
59
+ def to_pki_string_retrieve(request)
60
+ PkiBuilder.new.
61
+ append(:locale, request[:locale]).
62
+ append(:conversationId, request[:conversationId]).
63
+ append(:subMerchantExternalId, request[:subMerchantExternalId]).
64
+ get_request_string
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ module Iyzipay
2
+ module Model
3
+ module SubMerchantType
4
+ PERSONAL = 'PERSONAL'
5
+ PRIVATE_COMPANY = 'PRIVATE_COMPANY'
6
+ LIMITED_OR_JOINT_STOCK_COMPANY = 'LIMITED_OR_JOINT_STOCK_COMPANY'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module Iyzipay
2
+ module Model
3
+ class ThreedsInitialize < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/initialize3ds/ecom", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def to_pki_string(request)
11
+ PkiBuilder.new.append_super(super).
12
+ append_price(:price, request[:price]).
13
+ append_price(:paidPrice, request[:paidPrice]).
14
+ append(:installment, request[:installment]).
15
+ append(:paymentChannel, request[:paymentChannel]).
16
+ append(:basketId, request[:basketId]).
17
+ append(:paymentGroup, request[:paymentGroup]).
18
+ append(:paymentCard, PaymentCard.to_pki_string(request[:paymentCard])).
19
+ append(:buyer, Buyer.to_pki_string(request[:buyer])).
20
+ append(:shippingAddress, Address.to_pki_string(request[:shippingAddress])).
21
+ append(:billingAddress, Address.to_pki_string(request[:billingAddress])).
22
+ append_array(:basketItems, Basket.to_pki_string(request[:basketItems])).
23
+ append(:paymentSource, request[:paymentSource]).
24
+ get_request_string
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module Iyzipay
2
+ module Model
3
+ class ThreedsInitializePreAuth < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/initialize3ds/preauth/ecom", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def to_pki_string(request)
11
+ PkiBuilder.new.append_super(super).
12
+ append_price(:price, request[:price]).
13
+ append_price(:paidPrice, request[:paidPrice]).
14
+ append(:installment, request[:installment]).
15
+ append(:paymentChannel, request[:paymentChannel]).
16
+ append(:basketId, request[:basketId]).
17
+ append(:paymentGroup, request[:paymentGroup]).
18
+ append(:paymentCard, PaymentCard.to_pki_string(request[:paymentCard])).
19
+ append(:buyer, Buyer.to_pki_string(request[:buyer])).
20
+ append(:shippingAddress, Address.to_pki_string(request[:shippingAddress])).
21
+ append(:billingAddress, Address.to_pki_string(request[:billingAddress])).
22
+ append_array(:basketItems, Basket.to_pki_string(request[:basketItems])).
23
+ append(:paymentSource, request[:paymentSource]).
24
+ append(:callbackUrl, request[:callbackUrl]).
25
+ append(:posOrderId, request[:posOrderId]).
26
+ append(:connectorName, request[:connectorName]).
27
+ get_request_string
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ module Iyzipay
2
+ module Model
3
+ class ThreedsPayment < IyzipayResource
4
+
5
+ def create(request = {}, options)
6
+ pki_string = to_pki_string_create(request)
7
+ HttpClient.post("#{options.base_url}/payment/iyzipos/auth3ds/ecom", get_http_header(pki_string, options), request.to_json)
8
+ end
9
+
10
+ def retrieve(request = {}, options)
11
+ pki_string = to_pki_string_retrieve(request)
12
+ HttpClient.post("#{options.base_url}/payment/detail", get_http_header(pki_string, options), request.to_json)
13
+ end
14
+
15
+ def to_pki_string_create(request)
16
+ PkiBuilder.new.
17
+ append(:locale, request[:locale]).
18
+ append(:conversationId, request[:conversationId]).
19
+ append(:paymentId, request[:paymentId]).
20
+ append(:conversationData, request[:conversationData]).
21
+ get_request_string
22
+ end
23
+
24
+ def to_pki_string_retrieve(request)
25
+ PkiBuilder.new.
26
+ append(:locale, request[:locale]).
27
+ append(:conversationId, request[:conversationId]).
28
+ append(:paymentId, request[:paymentId]).
29
+ append(:paymentConversationId, request[:paymentConversationId]).
30
+ get_request_string
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ module Iyzipay
2
+ class Options
3
+ attr_accessor :api_key
4
+ attr_accessor :secret_key
5
+ attr_accessor :base_url
6
+ end
7
+ end
@@ -0,0 +1,101 @@
1
+ module Iyzipay
2
+ class PkiBuilder
3
+ attr_accessor :request_string
4
+
5
+ def initialize(request_string = '')
6
+ @request_string = request_string
7
+ end
8
+
9
+ def append_super(super_request_string)
10
+ unless super_request_string.nil?
11
+
12
+ s = super_request_string[1..-2]
13
+ if s.length > 0
14
+ result = @request_string + s
15
+ result << ','
16
+ end
17
+ @request_string = result
18
+ end
19
+ self
20
+ end
21
+
22
+ def append(key, value = nil)
23
+ unless value.nil?
24
+ append_key_value(key, value)
25
+ end
26
+ self
27
+ end
28
+
29
+ def append_price(key, value = nil)
30
+ unless value.nil?
31
+ append_key_value(key, format_price(value))
32
+ end
33
+ self
34
+ end
35
+
36
+ def append_array(key, array = nil)
37
+ unless array.nil?
38
+ appended_value = ''
39
+ array.each do |value|
40
+ appended_value << value
41
+ appended_value << ', '
42
+ end
43
+ end
44
+ append_key_value_array(key, appended_value)
45
+
46
+ self
47
+ end
48
+
49
+ def append_key_value(key, value)
50
+ @request_string = "#{@request_string}#{key}=#{value}," unless value.nil?
51
+ end
52
+
53
+ def append_key_value_array(key, value)
54
+ unless value.nil?
55
+ sub = ', '
56
+ value = value.gsub(/[#{sub}]+$/, '')
57
+ @request_string = "#{@request_string}#{key}=[#{value}],"
58
+ end
59
+
60
+ self
61
+ end
62
+
63
+ def append_prefix
64
+ @request_string = "[#{@request_string}]"
65
+ end
66
+
67
+ def remove_trailing_comma
68
+ sub = ','
69
+ @request_string = @request_string.gsub(/[#{sub}]+$/, '')
70
+ end
71
+
72
+ def get_request_string
73
+ remove_trailing_comma
74
+ append_prefix
75
+
76
+ @request_string
77
+ end
78
+
79
+ def format_price(price)
80
+ unless price.include? '.'
81
+ price = price+'.0'
82
+ end
83
+ sub_str_index = 0
84
+ price_reversed = price.reverse
85
+ i=0
86
+ while i < price.size do
87
+ if price_reversed[i] == '0'
88
+ sub_str_index = i + 1
89
+ elsif price_reversed[i] == '.'
90
+ price_reversed = '0' + price_reversed
91
+ break
92
+ else
93
+ break
94
+ end
95
+ i+=1
96
+ end
97
+ (price_reversed[sub_str_index..-1]).reverse
98
+ end
99
+
100
+ end
101
+ end