iyzipay-subscription-payments 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +17 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE +21 -0
  8. data/README.md +183 -0
  9. data/Rakefile +5 -0
  10. data/VERSION +1 -0
  11. data/contributors +2 -0
  12. data/examples/options.rb +4 -0
  13. data/examples/plan.rb +36 -0
  14. data/examples/product.rb +32 -0
  15. data/examples/subscription.rb +33 -0
  16. data/examples/subscription_checkout_form_initialize.rb +39 -0
  17. data/examples/subscription_initialize.rb +47 -0
  18. data/gemfiles/Gemfile.nokogiri-1.6.8.1 +7 -0
  19. data/iyzipay.gemspec +24 -0
  20. data/lib/iyzipay/http_client.rb +39 -0
  21. data/lib/iyzipay/iyzipay_resource.rb +60 -0
  22. data/lib/iyzipay/iyzipay_resource_v2.rb +39 -0
  23. data/lib/iyzipay/model/address.rb +17 -0
  24. data/lib/iyzipay/model/api_test.rb +10 -0
  25. data/lib/iyzipay/model/approval.rb +17 -0
  26. data/lib/iyzipay/model/basic_bkm.rb +17 -0
  27. data/lib/iyzipay/model/basic_bkm_initialize.rb +24 -0
  28. data/lib/iyzipay/model/basic_payment.rb +27 -0
  29. data/lib/iyzipay/model/basic_payment_post_auth.rb +20 -0
  30. data/lib/iyzipay/model/basic_payment_pre_auth.rb +27 -0
  31. data/lib/iyzipay/model/basic_threeds_initialize.rb +27 -0
  32. data/lib/iyzipay/model/basic_threeds_initialize_pre_auth.rb +27 -0
  33. data/lib/iyzipay/model/basic_threeds_payment.rb +18 -0
  34. data/lib/iyzipay/model/basket.rb +26 -0
  35. data/lib/iyzipay/model/basket_item_type.rb +8 -0
  36. data/lib/iyzipay/model/bin_number.rb +17 -0
  37. data/lib/iyzipay/model/bkm.rb +17 -0
  38. data/lib/iyzipay/model/bkm_initialize.rb +26 -0
  39. data/lib/iyzipay/model/bounced_bank_transfer_list.rb +17 -0
  40. data/lib/iyzipay/model/buyer.rb +25 -0
  41. data/lib/iyzipay/model/cancel.rb +20 -0
  42. data/lib/iyzipay/model/card.rb +36 -0
  43. data/lib/iyzipay/model/card_information.rb +17 -0
  44. data/lib/iyzipay/model/card_list.rb +17 -0
  45. data/lib/iyzipay/model/checkout_form.rb +17 -0
  46. data/lib/iyzipay/model/checkout_form_initialize.rb +31 -0
  47. data/lib/iyzipay/model/checkout_form_initialize_pre_auth.rb +30 -0
  48. data/lib/iyzipay/model/cross_booking_from_sub_merchant.rb +20 -0
  49. data/lib/iyzipay/model/cross_booking_to_sub_merchant.rb +20 -0
  50. data/lib/iyzipay/model/currency.rb +11 -0
  51. data/lib/iyzipay/model/disapproval.rb +17 -0
  52. data/lib/iyzipay/model/installment_details.rb +19 -0
  53. data/lib/iyzipay/model/installment_info.rb +18 -0
  54. data/lib/iyzipay/model/installment_prices.rb +19 -0
  55. data/lib/iyzipay/model/locale.rb +8 -0
  56. data/lib/iyzipay/model/pay_with_iyzico_initialize.rb +31 -0
  57. data/lib/iyzipay/model/pay_with_iyzico_retrieve.rb +17 -0
  58. data/lib/iyzipay/model/payment.rb +47 -0
  59. data/lib/iyzipay/model/payment_card.rb +22 -0
  60. data/lib/iyzipay/model/payment_channel.rb +14 -0
  61. data/lib/iyzipay/model/payment_group.rb +9 -0
  62. data/lib/iyzipay/model/payment_post_auth.rb +20 -0
  63. data/lib/iyzipay/model/payment_pre_auth.rb +47 -0
  64. data/lib/iyzipay/model/payout_completed_transaction_list.rb +17 -0
  65. data/lib/iyzipay/model/pecco_initialize.rb +27 -0
  66. data/lib/iyzipay/model/pecco_payment.rb +17 -0
  67. data/lib/iyzipay/model/refund.rb +22 -0
  68. data/lib/iyzipay/model/refund_charged_from_merchant.rb +20 -0
  69. data/lib/iyzipay/model/refund_reason.rb +10 -0
  70. data/lib/iyzipay/model/refund_to_balance.rb +18 -0
  71. data/lib/iyzipay/model/settlement_to_balance.rb +19 -0
  72. data/lib/iyzipay/model/sub_merchant.rb +72 -0
  73. data/lib/iyzipay/model/sub_merchant_type.rb +9 -0
  74. data/lib/iyzipay/model/threeds_initialize.rb +32 -0
  75. data/lib/iyzipay/model/threeds_initialize_pre_auth.rb +32 -0
  76. data/lib/iyzipay/model/threeds_payment.rb +34 -0
  77. data/lib/iyzipay/model/v2/checkout_form.rb +20 -0
  78. data/lib/iyzipay/model/v2/checkout_form_initialize.rb +21 -0
  79. data/lib/iyzipay/model/v2/plan.rb +33 -0
  80. data/lib/iyzipay/model/v2/product.rb +39 -0
  81. data/lib/iyzipay/model/v2/subscription.rb +60 -0
  82. data/lib/iyzipay/model/v2/subscription_initialize.rb +21 -0
  83. data/lib/iyzipay/model.rb +63 -0
  84. data/lib/iyzipay/options.rb +7 -0
  85. data/lib/iyzipay/pki_builder.rb +101 -0
  86. data/lib/iyzipay.rb +16 -0
  87. data/spec/api_test_spec.rb +28 -0
  88. data/spec/approval_spec.rb +41 -0
  89. data/spec/bin_number_spec.rb +42 -0
  90. data/spec/bkm_spec.rb +91 -0
  91. data/spec/builder/approval_builder.rb +18 -0
  92. data/spec/builder/card_builder.rb +27 -0
  93. data/spec/builder/checkout_form_builder.rb +75 -0
  94. data/spec/builder/payment_builder.rb +167 -0
  95. data/spec/builder/pecco_initialize_builder.rb +74 -0
  96. data/spec/builder/sub_merchant_builder.rb +91 -0
  97. data/spec/builder.rb +9 -0
  98. data/spec/cancel_spec.rb +72 -0
  99. data/spec/card_storage_spec.rb +153 -0
  100. data/spec/checkout_form_spec.rb +113 -0
  101. data/spec/disapproval_spec.rb +47 -0
  102. data/spec/installment_spec.rb +46 -0
  103. data/spec/pay_with_iyzico_spec.rb +109 -0
  104. data/spec/payment_spec.rb +320 -0
  105. data/spec/pecco_spec.rb +116 -0
  106. data/spec/refund_spec.rb +76 -0
  107. data/spec/refund_to_balance_spec.rb +37 -0
  108. data/spec/retrieve_transactions_spec.rb +55 -0
  109. data/spec/settlement_to_balance_spec.rb +40 -0
  110. data/spec/spec_helper.rb +81 -0
  111. data/spec/spec_options.rb +5 -0
  112. data/spec/sub_merchant_spec.rb +227 -0
  113. data/spec/threeds_payment_spec.rb +229 -0
  114. metadata +226 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 02f0d251badcba3d63fe063cea47bbb101550c4119b0c8856eab304a7f54b440
4
+ data.tar.gz: 02ef091125c11f57fb7f72b0addfcd9200e5fca55566d65d96b24a47534e2c2d
5
+ SHA512:
6
+ metadata.gz: ab98601aa36d738265d6e0904cccc50d2f1d3580b8674da81668ca12d1c0b72f297c00c66de139bb5a39c7783b32890e82a4ec1ac413b320a2046c7729c386ae
7
+ data.tar.gz: 6d7e0a08ee56aa421d3ff44ee7e3e5eda720090b94e4a1d3a8cb001a536379651c6d1da673527bb715bdf0e60f49653c7615a4e44095e7cec7da616a11b20428
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .DS_Store
2
+ tmp/*
3
+ .lock
4
+ .rvmrc
5
+ .vimrc
6
+ .redcar
7
+ .bundle
8
+ .rbx
9
+ .idea/
10
+ Gemfile.lock
11
+ .Gemfile.lock
12
+ tags
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ iyzipay
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: oyTMpNUPMM2ExVpmXHCHrMc04aCgMcp0gJwhcDHlTyy7HpJBHZS3abBUCOxQOtBj7RKir7BkMFH+XoQz2OoIt//2+S9yBDTf1Nt15KkcXvJq9fIXSiHgiqnQnnZTuE5M2LE287lqO3mGXcJvTaosxO6Wh9K6K6pA0nSOt7DE4foG53MfjX4no1aazrlIDGqZYO4Ml8cHqph02Kp2U5N/+f5V3EfhYp9QshGa3AeUx+gIcXaIbh2v9fz1mEYA3qPFL4Yi9c36p9tqwhPe62pEYBmo9pDziSShIoGZiWMAKFS8qJXXHlWFAYmt9tFLmSNyiiWl35JPjU7Wz5wC9xQHP/o3ZsIT23/UrI0xBZxtTA0eqoeNRERAUN5kARqhKM4UMWyp4ss7+gA69B6zO58HGu/8ZPVn7zQ6yhSrMSTU03DOl3z05koS5YDNLBDKv903jeNO54j31OMlNXht7ugLTP+DNO35vTitzUvxzvOCpVAGuqoYABfATweVMYRUYf+3m6ypBlEC3k3Z2WLaez2FFEfIZXikhVzjWrxiaKfMdzc2XRgr8Ea3KxPmOeYN4gULGZXQaZJ37xQKTRyAkCbt0G/xi2L4q5bDP9NuvRjeijKGtyarshIpOdb9nTEVm8C43+H3mq2Y9Dwtv9dl5DoNYcJjJMiJv1hbldthlInPTqo=
12
+ gem: iyzipay
13
+ on:
14
+ tags: true
15
+ repo: iyzico/iyzipay-ruby
16
+ skip_cleanup: true
17
+ script: rspec spec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
6
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 - iyzico Ödeme Hizmetleri A.Ş. (https://iyzico.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # iyzipay-ruby
2
+
3
+ [![Build Status](https://travis-ci.org/iyzico/iyzipay-ruby.svg?branch=master)](https://travis-ci.org/iyzico/iyzipay-ruby)
4
+
5
+ You can sign up for an iyzico account at https://iyzico.com
6
+
7
+ # Requirements
8
+
9
+ * Ruby 2.1 or newer
10
+ * rest-client
11
+
12
+ ## Note
13
+
14
+ Ruby 1.9.3 will not be supported in March 2018 for TLS 1.2 migration. Please upgrade your Ruby version to minimum 2.1.0. If you have any questions, please open an issue on Github or contact us at integration@iyzico.com.
15
+
16
+ # Installation
17
+
18
+ gem install iyzipay
19
+
20
+ ## Bundler
21
+
22
+ ``` ruby
23
+ source 'https://rubygems.org'
24
+
25
+ gem 'iyzipay'
26
+
27
+ ```
28
+
29
+ # Usage
30
+
31
+ ```ruby
32
+
33
+ before :all do
34
+ @options = Iyzipay::Options.new
35
+ @options.api_key = 'your api key'
36
+ @options.secret_key = 'your secret key'
37
+ @options.base_url = 'https://sandbox-api.iyzipay.com'
38
+ end
39
+
40
+ it 'should create payment' do
41
+ payment_card = {
42
+ cardHolderName: 'John Doe',
43
+ cardNumber: '5528790000000008',
44
+ expireYear: '2030',
45
+ expireMonth: '12',
46
+ cvc: '123',
47
+ registerCard: 0
48
+ }
49
+ buyer = {
50
+ id: 'BY789',
51
+ name: 'John',
52
+ surname: 'Doe',
53
+ identityNumber: '74300864791',
54
+ email: 'email@email.com',
55
+ gsmNumber: '+905350000000',
56
+ registrationDate: '2013-04-21 15:12:09',
57
+ lastLoginDate: '2015-10-05 12:43:35',
58
+ registrationAddress: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
59
+ city: 'Istanbul',
60
+ country: 'Turkey',
61
+ zipCode: '34732',
62
+ ip: '85.34.78.112'
63
+ }
64
+ address = {
65
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
66
+ zipCode: '34732',
67
+ contactName: 'John Doe',
68
+ city: 'Istanbul',
69
+ country: 'Turkey'
70
+ }
71
+
72
+ item1 = {
73
+ id: 'BI101',
74
+ name: 'Binocular',
75
+ category1: 'Collectibles',
76
+ category2: 'Accessories',
77
+ itemType: Iyzipay::Model::BasketItemType::PHYSICAL,
78
+ price: '0.3'
79
+ }
80
+ item2 = {
81
+ id: 'BI102',
82
+ name: 'Game code',
83
+ category1: 'Game',
84
+ category2: 'Online Game Items',
85
+ itemType: Iyzipay::Model::BasketItemType::VIRTUAL,
86
+ price: '0.5'
87
+ }
88
+ item3 = {
89
+ id: 'BI103',
90
+ name: 'Usb',
91
+ category1: 'Electronics',
92
+ category2: 'Usb / Cable',
93
+ itemType: Iyzipay::Model::BasketItemType::PHYSICAL,
94
+ price: '0.2'
95
+ }
96
+ request = {
97
+ locale: Iyzipay::Model::Locale::TR,
98
+ conversationId: '123456789',
99
+ price: '1.0',
100
+ paidPrice: '1.1',
101
+ installment: 1,
102
+ paymentChannel: Iyzipay::Model::PaymentChannel::WEB,
103
+ basketId: 'B67832',
104
+ paymentGroup: Iyzipay::Model::PaymentGroup::SUBSCRIPTION,
105
+ currency: Iyzipay::Model::Currency::TRY,
106
+ paymentCard: payment_card,
107
+ buyer: buyer,
108
+ billingAddress: address,
109
+ shippingAddress: address,
110
+ basketItems: [item1, item2, item3]
111
+ }
112
+ payment = Iyzipay::Model::Payment.new.create(request, @options)
113
+ begin
114
+ $stderr.puts payment.inspect
115
+ rescue
116
+ $stderr.puts 'oops'
117
+ raise
118
+ end
119
+ end
120
+ ```
121
+ See other samples under iyzipay-ruby/spec module.
122
+
123
+ Testing
124
+ =======
125
+
126
+ You can run specs with RSpec under spec module.
127
+
128
+ ### Mock test cards
129
+
130
+ Test cards that can be used to simulate a *successful* payment:
131
+
132
+ Card Number | Bank | Card Type
133
+ ----------- | ---- | ---------
134
+ 5890040000000016 | Akbank | Master Card (Debit)
135
+ 5526080000000006 | Akbank | Master Card (Credit)
136
+ 4766620000000001 | Denizbank | Visa (Debit)
137
+ 4603450000000000 | Denizbank | Visa (Credit)
138
+ 4729150000000005 | Denizbank Bonus | Visa (Credit)
139
+ 4987490000000002 | Finansbank | Visa (Debit)
140
+ 5311570000000005 | Finansbank | Master Card (Credit)
141
+ 9792020000000001 | Finansbank | Troy (Debit)
142
+ 9792030000000000 | Finansbank | Troy (Credit)
143
+ 5170410000000004 | Garanti Bankası | Master Card (Debit)
144
+ 5400360000000003 | Garanti Bankası | Master Card (Credit)
145
+ 374427000000003 | Garanti Bankası | American Express
146
+ 4475050000000003 | Halkbank | Visa (Debit)
147
+ 5528790000000008 | Halkbank | Master Card (Credit)
148
+ 4059030000000009 | HSBC Bank | Visa (Debit)
149
+ 5504720000000003 | HSBC Bank | Master Card (Credit)
150
+ 5892830000000000 | Türkiye İş Bankası | Master Card (Debit)
151
+ 4543590000000006 | Türkiye İş Bankası | Visa (Credit)
152
+ 4910050000000006 | Vakıfbank | Visa (Debit)
153
+ 4157920000000002 | Vakıfbank | Visa (Credit)
154
+ 5168880000000002 | Yapı ve Kredi Bankası | Master Card (Debit)
155
+ 5451030000000000 | Yapı ve Kredi Bankası | Master Card (Credit)
156
+
157
+ *Cross border* test cards:
158
+
159
+ Card Number | Country
160
+ ----------- | -------
161
+ 4054180000000007 | Non-Turkish (Debit)
162
+ 5400010000000004 | Non-Turkish (Credit)
163
+
164
+ Test cards to get specific *error* codes:
165
+
166
+ Card Number | Description
167
+ ----------- | -----------
168
+ 5406670000000009 | Success but cannot be cancelled, refund or post auth
169
+ 4111111111111129 | Not sufficient funds
170
+ 4129111111111111 | Do not honour
171
+ 4128111111111112 | Invalid transaction
172
+ 4127111111111113 | Lost card
173
+ 4126111111111114 | Stolen card
174
+ 4125111111111115 | Expired card
175
+ 4124111111111116 | Invalid cvc2
176
+ 4123111111111117 | Not permitted to card holder
177
+ 4122111111111118 | Not permitted to terminal
178
+ 4121111111111119 | Fraud suspect
179
+ 4120111111111110 | Pickup card
180
+ 4130111111111118 | General error
181
+ 4131111111111117 | Success but mdStatus is 0
182
+ 4141111111111115 | Success but mdStatus is 4
183
+ 4151111111111112 | 3dsecure initialize failed
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ task default: %w[test]
2
+
3
+ task :test do
4
+ puts "@TODO"
5
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.45
data/contributors ADDED
@@ -0,0 +1,2 @@
1
+ Yalcin Yenigun
2
+ Nurettin Bakkal
@@ -0,0 +1,4 @@
1
+ @options = Iyzipay::Options.new
2
+ @options.api_key = 'YOUR_API_KEY'
3
+ @options.secret_key = 'YOUR_SECRET_KEY'
4
+ @options.base_url = 'https://sandbox-api.iyzipay.com' # use https://api.iyzipay.com for production
data/examples/plan.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'iyzipay'
2
+ require_relative 'options.rb'
3
+
4
+ # -------------------------------------------------------------
5
+ # -------------------------------------------------------------
6
+ # Subscription Plan API end-point
7
+ # -------------------------------------------------------------
8
+ # -------------------------------------------------------------
9
+ plan = Iyzipay::Model::V2::Plan.new
10
+ # Create new plan
11
+ plan_create_params = {
12
+ locale: Iyzipay::Model::Locale::TR,
13
+ conversationId: '12341234',
14
+ productReferenceCode: 'YOUR_PRODUCT_REFERENCE_CODE',
15
+ name: 'Plan Name',
16
+ price: 100.00,
17
+ currencyCode: 'TL',
18
+ paymentInterval: 'MONTHLY',
19
+ paymentIntervalCount: 1,
20
+ trialPeriodDays: 7,
21
+ planPaymentType: 'RECURRING'
22
+ }
23
+ result = plan.create(plan_create_params, @options)
24
+ puts "Plan create: #{result}"
25
+
26
+ # Update plan
27
+ plan_update_params = {
28
+ locale: Iyzipay::Model::Locale::TR,
29
+ conversationId: '12341234',
30
+ pricingPlanReferenceCode: 'YOUR_PRICING_PLAN_REFERENCE_CODE',
31
+ name: 'Update Plan',
32
+ trialPeriodDays: 3,
33
+ }
34
+
35
+ result = plan.update(plan_update_params, @options)
36
+ puts "Plan update: #{result}"
@@ -0,0 +1,32 @@
1
+ require 'iyzipay'
2
+ require_relative 'options.rb'
3
+
4
+ # -------------------------------------------------------------
5
+ # -------------------------------------------------------------
6
+ # Subscription Product API end-point
7
+ # -------------------------------------------------------------
8
+ # -------------------------------------------------------------
9
+ product = Iyzipay::Model::V2::Product.new
10
+ # List all products
11
+ result = product.list(@options)
12
+ puts "Product list: #{result.inspect}"
13
+
14
+ # Create new product
15
+ product_create_params = {
16
+ locale: Iyzipay::Model::Locale::TR,
17
+ conversationId: '12341234',
18
+ name: 'New Product',
19
+ description: 'My Product'
20
+ }
21
+ result = product.create(product_create_params, @options)
22
+ puts "Product create: #{result}"
23
+
24
+ # Update product
25
+ product_update_params = {
26
+ locale: Iyzipay::Model::Locale::TR,
27
+ productReferenceCode: 'YOUR_PRODUCT_REFERENCE_CODE',
28
+ name: 'Update Product',
29
+ description: 'My Product'
30
+ }
31
+ result = product.update(product_update_params, @options)
32
+ puts "Product update: #{result}"
@@ -0,0 +1,33 @@
1
+ require 'iyzipay'
2
+ require_relative 'options.rb'
3
+
4
+ # -------------------------------------------------------------
5
+ # -------------------------------------------------------------
6
+ # Subscription Operations API end-point
7
+ # -------------------------------------------------------------
8
+ # -------------------------------------------------------------
9
+ subscription = Iyzipay::Model::V2::Subscription.new
10
+
11
+ # Activate
12
+ activate_params = {
13
+ subscriptionReferenceCode: 'YOUR_CODE',
14
+ }
15
+ response = subscription.activate(activate_params, @options)
16
+ puts "Subscription activate: #{response}"
17
+
18
+ # Cancel
19
+ cancel_params = {
20
+ locale: Iyzipay::Model::Locale::TR,
21
+ conversationId: '1234512345',
22
+ subscriptionReferenceCode: 'YOUR_CODE'
23
+ }
24
+ response = subscription.cancel(cancel_params, @options)
25
+ puts "Subscription cancel: #{response}"
26
+
27
+ # Retry
28
+ retry_params = {
29
+ referenceCode: 'YOUR_CODE'
30
+ }
31
+
32
+ result = subscription.retry(retry_params, @options)
33
+ puts "Subscription retry: #{result}"
@@ -0,0 +1,39 @@
1
+ require 'iyzipay'
2
+ require_relative 'options.rb'
3
+
4
+ # -------------------------------------------------------------
5
+ # -------------------------------------------------------------
6
+ # Subscription Checkout Form API end-point
7
+ # -------------------------------------------------------------
8
+ # -------------------------------------------------------------
9
+ checkout_form = Iyzipay::Model::V2::CheckoutFormInitialize.new
10
+
11
+ # Address Params
12
+ address = {
13
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
14
+ zipCode: '34732',
15
+ contactName: 'John Doe',
16
+ city: 'Istanbul',
17
+ country: 'Turkey'
18
+ }
19
+
20
+ buyer = {
21
+ name: 'John',
22
+ surname: 'Doe',
23
+ email: 'john.doe@gmail.com',
24
+ gsmNumber: '+905555555555',
25
+ identityNumber: '16038567668',
26
+ billingAddress: address,
27
+ shippingAddress: address
28
+ }
29
+ # Checkout form initialize params
30
+ checkout_form_params = {
31
+ locale: Iyzipay::Model::Locale::TR,
32
+ conversationId: '1234512345',
33
+ callbackUrl: 'YOUR_CALLBACK_URL',
34
+ pricingPlanReferenceCode: 'YOUR_PRICING_PLAN_REFERENCE_CODE',
35
+ customer: buyer
36
+ }
37
+
38
+ result = checkout_form.create(checkout_form_params, @options)
39
+ puts "Result: #{result}"
@@ -0,0 +1,47 @@
1
+ require 'iyzipay'
2
+ require_relative 'options.rb'
3
+
4
+ # -------------------------------------------------------------
5
+ # -------------------------------------------------------------
6
+ # Subscription Initialize API end-point
7
+ # -------------------------------------------------------------
8
+ # -------------------------------------------------------------
9
+ subscription = Iyzipay::Model::V2::SubscriptionInitialize.new
10
+ # Address
11
+ address = {
12
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
13
+ zipCode: '34732',
14
+ contactName: 'John Doe',
15
+ city: 'Istanbul',
16
+ country: 'Turkey'
17
+ }
18
+
19
+ buyer = {
20
+ name: 'John',
21
+ surname: 'Doe',
22
+ email: 'john.doe@gmail.com',
23
+ gsmNumber: '+905422073160',
24
+ identityNumber: '16038567668',
25
+ billingAddress: address,
26
+ shippingAddress: address
27
+ }
28
+ # Card
29
+ card = {
30
+ cardHolderName: 'John Doe',
31
+ cardNumber: '5528790000000008',
32
+ expireMonth: '12',
33
+ expireYear: '2030',
34
+ cvc: '123',
35
+ registerConsumerCard: true
36
+ }
37
+ # Create new product
38
+ checkout_form_params = {
39
+ locale: Iyzipay::Model::Locale::TR,
40
+ conversationId: '1234512345',
41
+ callbackUrl: 'https://iyzipay-subscription.herokuapp.com/subscriptions/callback',
42
+ pricingPlanReferenceCode: 'YOUR_PRICING_PLAN_REFERENCE_CODE',
43
+ customer: buyer,
44
+ paymentCard: card
45
+ }
46
+ result = subscription.create(checkout_form_params, @options)
47
+ puts "Subscription create: #{result}"
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ group :development do
6
+ gem 'nokogiri', '1.6.8.1'
7
+ end
data/iyzipay.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'iyzipay-subscription-payments'
6
+ s.version = '1.0.1'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.required_ruby_version = '>= 1.9.3'
9
+ s.summary = %q{iyzipay api ruby client for subscriptions feature}
10
+ s.description = %q{iyzipay api ruby client for subscriptions feature. You can sign up for an iyzico account at https://iyzico.com}
11
+ s.authors = ['Iyzico', 'Muhammed Ali Arici']
12
+ s.email = 'm.ali.arici01@gmail.com'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
15
+ s.homepage = 'https://github.com/256-byte/iyzipay-ruby'
16
+ s.license = 'MIT'
17
+
18
+ s.add_runtime_dependency 'rack', '~> 2.0'
19
+ s.add_runtime_dependency 'rest-client', '~> 2.1'
20
+ s.add_development_dependency 'rspec', '~>3.5.0'
21
+ s.add_development_dependency 'rspec-rails', '~>3.5.0'
22
+ s.add_development_dependency 'nokogiri', '~>1.8.2'
23
+ s.require_paths = ['lib']
24
+ end
@@ -0,0 +1,39 @@
1
+ module Iyzipay
2
+ class HttpClient
3
+ def self.get(url, header={})
4
+ RestClient.get(url, header)
5
+ end
6
+
7
+ def self.post(url, header, content)
8
+ RestClient.post(url, content, header)
9
+ end
10
+
11
+ def self.put(url, header, content)
12
+ RestClient.put(url, content, header)
13
+ end
14
+
15
+ def self.delete(url, headers={}, content, &block)
16
+ RestClient::Request.execute(:method => :delete, :url => url, :payload => content, :headers => headers, &block)
17
+ end
18
+
19
+ # Those methods to get failed status requests' responses
20
+ def self.get_even_on_error(url, header={})
21
+ RestClient.get(url, header) do |response, request, result|
22
+ {response: response, request: request, result: result}
23
+ end
24
+ end
25
+
26
+ def self.post_even_on_error(url, header, content)
27
+ RestClient.post(url, content, header) do |response, request, result|
28
+ {response: response, request: request, result: result}
29
+ end
30
+ end
31
+
32
+ def self.put_even_on_error(url, header, content)
33
+ RestClient.put(url, content, header) do |response, request, result|
34
+ {response: response, request: request, result: result}
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ module Iyzipay
2
+ class IyzipayResource
3
+
4
+ AUTHORIZATION_HEADER_NAME = 'Authorization'
5
+ RANDOM_HEADER_NAME = 'x-iyzi-rnd';
6
+ AUTHORIZATION_HEADER_STRING = 'IYZWS %s:%s'
7
+ RANDOM_STRING_SIZE = 8
8
+ RANDOM_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
9
+
10
+ def get_http_header(pki_string = nil, options = nil, authorize_request = true)
11
+ header = {:accept => 'application/json',
12
+ :'content-type' => 'application/json'}
13
+
14
+ if authorize_request
15
+ random_header_value = random_string(RANDOM_STRING_SIZE)
16
+ header[:'Authorization'] = "#{prepare_authorization_string(pki_string, random_header_value, options)}"
17
+ header[:'x-iyzi-rnd'] = "#{random_header_value}"
18
+ header[:'x-iyzi-client-version'] = 'iyzipay-ruby-1.0.45'
19
+ end
20
+
21
+ header
22
+ end
23
+
24
+ def get_plain_http_header
25
+ get_http_header(nil, false)
26
+ end
27
+
28
+ def prepare_authorization_string(pki_string, random_header_value, options)
29
+ hash_digest = calculate_hash(pki_string, random_header_value, options)
30
+ format_header_string(options.api_key, hash_digest)
31
+ end
32
+
33
+ def json_decode(response, raw_result)
34
+ json_result = JSON::parse(raw_result)
35
+ response.from_json(json_result)
36
+ end
37
+
38
+ def calculate_hash(pki_string, random_header_value, options)
39
+ Digest::SHA1.base64digest("#{options.api_key}#{random_header_value}#{options.secret_key}#{pki_string}")
40
+ end
41
+
42
+ def format_header_string(*args)
43
+ sprintf(AUTHORIZATION_HEADER_STRING, *args)
44
+ end
45
+
46
+ def random_string(string_length)
47
+ random_string = ''
48
+ string_length.times do
49
+ random_string << RANDOM_CHARS.split('').sample
50
+ end
51
+ random_string
52
+ end
53
+
54
+ def to_pki_string(request)
55
+ PkiBuilder.new.append(:locale, request[:locale]).
56
+ append(:conversationId, request[:conversationId]).
57
+ get_request_string
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iyzipay
4
+ class IyzipayResourceV2 < IyzipayResource
5
+ AUTHORIZATION_HEADER_STRING = 'IYZWSv2'
6
+
7
+ def get_http_header(options, uri, pki_string = nil, authorize_request = true)
8
+ header = {
9
+ accept: 'application/json',
10
+ 'content-type': 'application/json'
11
+ }
12
+ if authorize_request
13
+ random_header_value = random_string(RANDOM_STRING_SIZE)
14
+ authorization = prepare_authorization_string(pki_string, random_header_value, options, uri).to_s
15
+ header[:Authorization] = authorization
16
+ header[:'x-iyzi-rnd'] = random_header_value.to_s
17
+ header[:'x-iyzi-client-version'] = 'iyzipay-ruby-1.0.45'
18
+ end
19
+
20
+ header
21
+ end
22
+
23
+ def prepare_authorization_string(pki_string, random_header_value, options, uri)
24
+ hash_digest = calculate_hash(pki_string, random_header_value, options, uri)
25
+ "#{AUTHORIZATION_HEADER_STRING} #{hash_digest}"
26
+ end
27
+
28
+ def calculate_hash(pki_string, random_header_value, options, uri)
29
+ data = "#{random_header_value}#{uri}#{pki_string}"
30
+ signature = OpenSSL::HMAC.hexdigest('SHA256', options.secret_key, data)
31
+ authorization_params = [
32
+ 'apiKey:' + options.api_key,
33
+ 'randomKey:' + random_header_value,
34
+ 'signature:' + signature
35
+ ]
36
+ Base64.strict_encode64(authorization_params.join('&'))
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ module Iyzipay
2
+ module Model
3
+ class Address
4
+ def self.to_pki_string(request)
5
+ unless request.nil?
6
+ PkiBuilder.new.
7
+ append(:address, request[:address]).
8
+ append(:zipCode, request[:zipCode]).
9
+ append(:contactName, request[:contactName]).
10
+ append(:city, request[:city]).
11
+ append(:country, request[:country]).
12
+ get_request_string
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Iyzipay
2
+ module Model
3
+ class ApiTest < IyzipayResource
4
+
5
+ def retrieve(options)
6
+ HttpClient.get("#{options.base_url}/payment/test")
7
+ end
8
+ end
9
+ end
10
+ end