iyzipay 1.0.36 → 1.0.39

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.
@@ -0,0 +1,74 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ module Builder
6
+ class PeccoInitializeBuilder
7
+
8
+ def create_pecco_initialize(options)
9
+ buyer = {
10
+ id: 'BY789',
11
+ name: 'John',
12
+ surname: 'Doe',
13
+ identityNumber: '74300864791',
14
+ email: 'email@email.com',
15
+ gsmNumber: '+905350000000',
16
+ registrationDate: '2013-04-21 15:12:09',
17
+ lastLoginDate: '2015-10-05 12:43:35',
18
+ registrationAddress: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
19
+ city: 'Istanbul',
20
+ country: 'Turkey',
21
+ zipCode: '34732',
22
+ ip: '85.34.78.112'
23
+ }
24
+ address = {
25
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
26
+ zipCode: '34732',
27
+ contactName: 'John Doe',
28
+ city: 'Istanbul',
29
+ country: 'Turkey'
30
+ }
31
+
32
+ item1 = {
33
+ id: 'BI101',
34
+ name: 'Binocular',
35
+ category1: 'Collectibles',
36
+ category2: 'Accessories',
37
+ itemType: Iyzipay::Model::BasketItemType::PHYSICAL,
38
+ price: '30000'
39
+ }
40
+ item2 = {
41
+ id: 'BI102',
42
+ name: 'Game code',
43
+ category1: 'Game',
44
+ category2: 'Online Game Items',
45
+ itemType: Iyzipay::Model::BasketItemType::VIRTUAL,
46
+ price: '50000'
47
+ }
48
+ item3 = {
49
+ id: 'BI103',
50
+ name: 'Usb',
51
+ category1: 'Electronics',
52
+ category2: 'Usb / Cable',
53
+ itemType: Iyzipay::Model::BasketItemType::PHYSICAL,
54
+ price: '20000'
55
+ }
56
+ request = {
57
+ locale: Iyzipay::Model::Locale::TR,
58
+ conversationId: '123456789',
59
+ price: '100000',
60
+ paidPrice: '120000',
61
+ basketId: 'B67832',
62
+ paymentGroup: Iyzipay::Model::PaymentGroup::LISTING,
63
+ callbackUrl: 'https://www.merchant.com/callback',
64
+ currency: Iyzipay::Model::Currency::IRR,
65
+ buyer: buyer,
66
+ billingAddress: address,
67
+ shippingAddress: address,
68
+ basketItems: [item1, item2, item3]
69
+ }
70
+ pecco_initialize = Iyzipay::Model::PeccoInitialize.new.create(request, options)
71
+ JSON.parse(pecco_initialize)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,91 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ module Builder
6
+ class SubMerchantBuilder
7
+
8
+ def create_personal_sub_merchant(options)
9
+ random_number = Random.rand(11**11).to_s
10
+ request = {
11
+ locale: Iyzipay::Model::Locale::TR,
12
+ conversationId: '123456789',
13
+ subMerchantExternalId: 'B' + random_number,
14
+ subMerchantType: Iyzipay::Model::SubMerchantType::PERSONAL,
15
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
16
+ contactName: 'John',
17
+ contactSurname: 'Doe',
18
+ email: random_number + '@email.com',
19
+ gsmNumber: '+905350000000',
20
+ name: 'John\'s market',
21
+ iban: 'TR180006200119000006672315',
22
+ identityNumber: random_number,
23
+ currency: Iyzipay::Model::Currency::TRY
24
+ }
25
+ sub_merchant = Iyzipay::Model::SubMerchant.new.create(request, options)
26
+ JSON.parse(sub_merchant)
27
+ end
28
+
29
+ def create_private_sub_merchant(options)
30
+ random_number = Random.rand(11**11).to_s
31
+ request = {
32
+ locale: Iyzipay::Model::Locale::TR,
33
+ conversationId: '123456789',
34
+ subMerchantExternalId: 'B' + random_number,
35
+ subMerchantType: Iyzipay::Model::SubMerchantType::PRIVATE_COMPANY,
36
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
37
+ taxOffice: 'Tax office',
38
+ legalCompanyTitle: 'John Doe inc',
39
+ email: random_number + '@email.com',
40
+ gsmNumber: '+905350000000',
41
+ name: 'John\'s market',
42
+ iban: 'TR180006200119000006672315',
43
+ identityNumber: '31300864726',
44
+ currency: Iyzipay::Model::Currency::TRY
45
+ }
46
+ sub_merchant = Iyzipay::Model::SubMerchant.new.create(request, options)
47
+ JSON.parse(sub_merchant)
48
+ end
49
+
50
+ def create_limited_sub_merchant(options)
51
+ random_number = Random.rand(11**11).to_s
52
+ request = {
53
+ locale: Iyzipay::Model::Locale::TR,
54
+ conversationId: '123456789',
55
+ subMerchantExternalId: 'B' + random_number,
56
+ subMerchantType: Iyzipay::Model::SubMerchantType::LIMITED_OR_JOINT_STOCK_COMPANY,
57
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
58
+ taxOffice: 'Tax office',
59
+ taxNumber: '9261877',
60
+ legalCompanyTitle: 'XYZ inc',
61
+ email: 'email@submerchantemail.com',
62
+ gsmNumber: '+905350000000',
63
+ name: 'John\'s market',
64
+ iban: 'TR180006200119000006672315',
65
+ currency: Iyzipay::Model::Currency::TRY
66
+ }
67
+ sub_merchant = Iyzipay::Model::SubMerchant.new.create(request, options)
68
+ JSON.parse(sub_merchant)
69
+ end
70
+
71
+ def create_limited_sub_merchant_with_external_key(external_key, options)
72
+ request = {
73
+ locale: Iyzipay::Model::Locale::TR,
74
+ conversationId: '123456789',
75
+ subMerchantExternalId: external_key,
76
+ subMerchantType: Iyzipay::Model::SubMerchantType::LIMITED_OR_JOINT_STOCK_COMPANY,
77
+ address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
78
+ taxOffice: 'Tax office',
79
+ taxNumber: '9261877',
80
+ legalCompanyTitle: 'XYZ inc',
81
+ email: 'email@submerchantemail.com',
82
+ gsmNumber: '+905350000000',
83
+ name: 'John\'s market',
84
+ iban: 'TR180006200119000006672315',
85
+ currency: Iyzipay::Model::Currency::TRY
86
+ }
87
+ sub_merchant = Iyzipay::Model::SubMerchant.new.create(request, options)
88
+ JSON.parse(sub_merchant)
89
+ end
90
+ end
91
+ end
@@ -1,25 +1,37 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative 'spec_helper'
4
+ require_relative 'builder'
4
5
 
5
6
  RSpec.describe 'Iyzipay' do
6
7
  before :all do
7
8
  @options = Iyzipay::Options.new
8
- @options.api_key = 'your api key'
9
- @options.secret_key = 'your secret key'
10
- @options.base_url = 'https://sandbox-api.iyzipay.com'
9
+ @options.api_key = SpecOptions::API_KEY
10
+ @options.secret_key = SpecOptions::SECRET_KEY
11
+ @options.base_url = SpecOptions::BASE_URL
11
12
  end
12
13
 
13
14
  it 'should cancel payment' do
15
+ payment = Builder::PaymentBuilder.new.create_standard_listing_payment(@options)
16
+
14
17
  request = {
15
18
  locale: Iyzipay::Model::Locale::TR,
16
19
  conversationId: '123456789',
17
- paymentId: '1',
20
+ paymentId: payment['paymentId'],
18
21
  ip: '85.34.78.112'
19
22
  }
20
23
  cancel = Iyzipay::Model::Cancel.new.create(request, @options)
21
24
  begin
22
- $stderr.puts cancel.inspect
25
+ $stdout.puts cancel.inspect
26
+ cancel = JSON.parse(cancel)
27
+ expect(cancel['status']).to eq('success')
28
+ expect(cancel['locale']).to eq('tr')
29
+ expect(cancel['systemTime']).not_to be_nil
30
+ expect(cancel['conversationId']).to eq('123456789')
31
+ expect(cancel['paymentId']).to eq(payment['paymentId'])
32
+ expect(cancel['price']).to eq(1.10000000)
33
+ expect(cancel['currency']).to eq('TRY')
34
+ expect(cancel['authCode']).to eq('mock00001iyziauthcd')
23
35
  rescue
24
36
  $stderr.puts 'oops'
25
37
  raise
@@ -1,13 +1,14 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative 'spec_helper'
4
+ require_relative 'builder'
4
5
 
5
6
  RSpec.describe 'Iyzipay' do
6
7
  before :all do
7
8
  @options = Iyzipay::Options.new
8
- @options.api_key = 'your api key'
9
- @options.secret_key = 'your secret key'
10
- @options.base_url = 'https://sandbox-api.iyzipay.com'
9
+ @options.api_key = SpecOptions::API_KEY
10
+ @options.secret_key = SpecOptions::SECRET_KEY
11
+ @options.base_url = SpecOptions::BASE_URL
11
12
  end
12
13
 
13
14
  it 'should create user and add card' do
@@ -27,14 +28,33 @@ RSpec.describe 'Iyzipay' do
27
28
  }
28
29
  card = Iyzipay::Model::Card.new.create(request, @options)
29
30
  begin
30
- $stderr.puts card.inspect
31
+ $stdout.puts card.inspect
32
+ card = JSON.parse(card)
33
+ expect(card['status']).to eq('success')
34
+ expect(card['locale']).to eq('tr')
35
+ expect(card['systemTime']).not_to be_nil
36
+ expect(card['conversationId']).to eq('123456789')
37
+ expect(card['externalId']).to eq('external id')
38
+ expect(card['email']).to eq('email@email.com')
39
+ expect(card['cardUserKey']).to eq(card['cardUserKey'])
40
+ expect(card['cardToken']).to eq(card['cardToken'])
41
+ expect(card['cardAlias']).to eq('card alias')
42
+ expect(card['binNumber']).to eq('552879')
43
+ expect(card['cardType']).to eq('CREDIT_CARD')
44
+ expect(card['cardAssociation']).to eq('MASTER_CARD')
45
+ expect(card['cardFamily']).to eq('Paraf')
46
+ expect(card['cardBankCode']).to eq(12)
47
+ expect(card['cardBankName']).to eq('Halk Bankası')
31
48
  rescue
32
49
  $stderr.puts 'oops'
33
50
  raise
34
51
  end
35
52
  end
36
53
 
37
- it 'should create card' do
54
+ it 'should create card and add card to existing user' do
55
+ # create card user
56
+ card = Builder::CardBuilder.new.create_card(@options)
57
+
38
58
  card_information = {
39
59
  cardAlias: 'card alias',
40
60
  cardHolderName: 'John Doe',
@@ -46,12 +66,27 @@ RSpec.describe 'Iyzipay' do
46
66
  locale: Iyzipay::Model::Locale::TR,
47
67
  conversationId: '123456789',
48
68
  email: 'email@email.com',
49
- cardUserKey: 'card user key',
69
+ cardUserKey: card['cardUserKey'],
50
70
  card: card_information
51
71
  }
52
72
  card = Iyzipay::Model::Card.new.create(request, @options)
53
73
  begin
54
- $stderr.puts card.inspect
74
+ $stdout.puts card.inspect
75
+ card = JSON.parse(card)
76
+ expect(card['status']).to eq('success')
77
+ expect(card['locale']).to eq('tr')
78
+ expect(card['systemTime']).not_to be_nil
79
+ expect(card['conversationId']).to eq('123456789')
80
+ expect(card['email']).to eq('email@email.com')
81
+ expect(card['cardUserKey']).to eq(card['cardUserKey'])
82
+ expect(card['cardToken']).to eq(card['cardToken'])
83
+ expect(card['cardAlias']).to eq('card alias')
84
+ expect(card['binNumber']).to eq('552879')
85
+ expect(card['cardType']).to eq('CREDIT_CARD')
86
+ expect(card['cardAssociation']).to eq('MASTER_CARD')
87
+ expect(card['cardFamily']).to eq('Paraf')
88
+ expect(card['cardBankCode']).to eq(12)
89
+ expect(card['cardBankName']).to eq('Halk Bankası')
55
90
  rescue
56
91
  $stderr.puts 'oops'
57
92
  raise
@@ -59,15 +94,23 @@ RSpec.describe 'Iyzipay' do
59
94
  end
60
95
 
61
96
  it 'should delete card' do
97
+ # create card
98
+ card = Builder::CardBuilder.new.create_card(@options)
99
+
62
100
  request = {
63
101
  locale: Iyzipay::Model::Locale::TR,
64
102
  conversationId: '123456789',
65
- cardToken: 'card token',
66
- cardUserKey: 'card user key'
103
+ cardToken: card['cardToken'],
104
+ cardUserKey: card['cardUserKey']
67
105
  }
68
106
  card = Iyzipay::Model::Card.new.delete(request, @options)
69
107
  begin
70
- $stderr.puts card.inspect
108
+ $stdout.puts card.inspect
109
+ card = JSON.parse(card)
110
+ expect(card['status']).to eq('success')
111
+ expect(card['locale']).to eq('tr')
112
+ expect(card['systemTime']).not_to be_nil
113
+ expect(card['conversationId']).to eq('123456789')
71
114
  rescue
72
115
  $stderr.puts 'oops'
73
116
  raise
@@ -75,14 +118,30 @@ RSpec.describe 'Iyzipay' do
75
118
  end
76
119
 
77
120
  it 'should retrieve card' do
121
+ card = Builder::CardBuilder.new.create_card(@options)
122
+
78
123
  request = {
79
124
  locale: Iyzipay::Model::Locale::TR,
80
125
  conversationId: '123456789',
81
- cardUserKey: 'card user key'
126
+ cardUserKey: card['cardUserKey']
82
127
  }
83
128
  card_list = Iyzipay::Model::CardList.new.retrieve(request, @options)
84
129
  begin
85
- $stderr.puts card_list.inspect
130
+ $stdout.puts card_list.inspect
131
+ card_list = JSON.parse(card_list)
132
+ expect(card_list['status']).to eq('success')
133
+ expect(card_list['locale']).to eq('tr')
134
+ expect(card_list['systemTime']).not_to be_nil
135
+ expect(card_list['conversationId']).to eq('123456789')
136
+ expect(card_list['cardUserKey']).to eq(card['cardUserKey'])
137
+ expect(card_list['cardDetails'][0]['cardToken']).to eq(card['cardToken'])
138
+ expect(card_list['cardDetails'][0]['cardAlias']).to eq('card alias')
139
+ expect(card_list['cardDetails'][0]['binNumber']).to eq('552879')
140
+ expect(card_list['cardDetails'][0]['cardType']).to eq('CREDIT_CARD')
141
+ expect(card_list['cardDetails'][0]['cardAssociation']).to eq('MASTER_CARD')
142
+ expect(card_list['cardDetails'][0]['cardFamily']).to eq('Paraf')
143
+ expect(card_list['cardDetails'][0]['cardBankCode']).to eq(12)
144
+ expect(card_list['cardDetails'][0]['cardBankName']).to eq('Halk Bankası')
86
145
  rescue
87
146
  $stderr.puts 'oops'
88
147
  raise
@@ -1,16 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative 'spec_helper'
4
+ require_relative 'builder'
4
5
 
5
6
  RSpec.describe 'Iyzipay' do
6
7
  before :all do
7
8
  @options = Iyzipay::Options.new
8
- @options.api_key = 'your api key'
9
- @options.secret_key = 'your secret key'
10
- @options.base_url = 'https://sandbox-api.iyzipay.com'
9
+ @options.api_key = SpecOptions::API_KEY
10
+ @options.secret_key = SpecOptions::SECRET_KEY
11
+ @options.base_url = SpecOptions::BASE_URL
11
12
  end
12
13
 
13
- it 'should initialize checkout form' do
14
+ it 'should initialize checkout form for standard merchant' do
14
15
  buyer = {
15
16
  id: 'BY789',
16
17
  name: 'John',
@@ -65,7 +66,7 @@ RSpec.describe 'Iyzipay' do
65
66
  paidPrice: '1.2',
66
67
  currency: Iyzipay::Model::Currency::TRY,
67
68
  basketId: 'B67832',
68
- paymentGroup: Iyzipay::Model::PaymentGroup::PRODUCT,
69
+ paymentGroup: Iyzipay::Model::PaymentGroup::LISTING,
69
70
  callbackUrl: 'https://www.merchant.com/callback',
70
71
  enabledInstallments: [2, 3, 6, 9],
71
72
  buyer: buyer,
@@ -76,7 +77,13 @@ RSpec.describe 'Iyzipay' do
76
77
  checkout_form_initialize = Iyzipay::Model::CheckoutFormInitialize.new.create(request, @options)
77
78
 
78
79
  begin
79
- $stderr.puts checkout_form_initialize.inspect
80
+ $stdout.puts checkout_form_initialize.inspect
81
+ checkout_form_initialize = JSON.parse(checkout_form_initialize)
82
+ expect(checkout_form_initialize['status']).to eq('success')
83
+ expect(checkout_form_initialize['locale']).to eq('tr')
84
+ expect(checkout_form_initialize['systemTime']).not_to be_nil
85
+ expect(checkout_form_initialize['token']).not_to be_nil
86
+ expect(checkout_form_initialize['checkoutFormContent']).not_to be_nil
80
87
  rescue
81
88
  $stderr.puts 'oops'
82
89
  raise
@@ -84,14 +91,17 @@ RSpec.describe 'Iyzipay' do
84
91
  end
85
92
 
86
93
  it 'should retrieve checkout form result' do
94
+ # This test needs manual on sandbox environment. So it does not contain any assertions.
95
+ checkout_form_initialize = Builder::CheckoutFormBuilder.new.create_checkout_form_initialize(@options)
96
+
87
97
  request = {
88
98
  locale: Iyzipay::Model::Locale::TR,
89
99
  conversationId: '123456789',
90
- token: 'token'
100
+ token: checkout_form_initialize['token']
91
101
  }
92
102
  checkout_form_payment = Iyzipay::Model::CheckoutForm.new.retrieve(request, @options)
93
103
  begin
94
- $stderr.puts checkout_form_payment.inspect
104
+ $stdout.puts checkout_form_payment.inspect
95
105
  rescue
96
106
  $stderr.puts 'oops'
97
107
  raise
@@ -1,24 +1,41 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require_relative 'spec_helper'
4
+ require_relative 'builder'
4
5
 
5
6
  RSpec.describe 'Iyzipay' do
6
7
  before :all do
7
8
  @options = Iyzipay::Options.new
8
- @options.api_key = 'your api key'
9
- @options.secret_key = 'your secret key'
10
- @options.base_url = 'https://sandbox-api.iyzipay.com'
9
+ @options.api_key = SpecOptions::API_KEY
10
+ @options.secret_key = SpecOptions::SECRET_KEY
11
+ @options.base_url = SpecOptions::BASE_URL
11
12
  end
12
13
 
13
14
  it 'should disapprove payment item' do
15
+ # create sub merchant
16
+ sub_merchant = Builder::SubMerchantBuilder.new.create_personal_sub_merchant(@options)
17
+
18
+ # create payment
19
+ payment = Builder::PaymentBuilder.new.create_marketplace_payment(@options, sub_merchant['subMerchantKey'])
20
+
21
+ # approve payment
22
+ Builder::ApprovalBuilder.new.create_approval(@options, payment['itemTransactions'][0]['paymentTransactionId'])
23
+
24
+ # disapprove payment
14
25
  request = {
15
26
  locale: Iyzipay::Model::Locale::TR,
16
27
  conversationId: '123456789',
17
- paymentTransactionId: '1'
28
+ paymentTransactionId: payment['itemTransactions'][0]['paymentTransactionId']
18
29
  }
19
30
  disapproval = Iyzipay::Model::Disapproval.new.create(request, @options)
20
31
  begin
21
- $stderr.puts disapproval.inspect
32
+ $stdout.puts disapproval.inspect
33
+ disapproval = JSON.parse(disapproval)
34
+ expect(disapproval['status']).to eq('success')
35
+ expect(disapproval['locale']).to eq('tr')
36
+ expect(disapproval['systemTime']).not_to be_nil
37
+ expect(disapproval['conversationId']).to eq('123456789')
38
+ expect(disapproval['paymentTransactionId']).to eq(payment['itemTransactions'][0]['paymentTransactionId'])
22
39
  rescue
23
40
  $stderr.puts 'oops'
24
41
  raise