pixelpay_sdk 1.0.0.pre.beta.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.
- checksums.yaml +7 -0
- data/.rubocop.yml +40 -0
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +19 -0
- data/Rakefile +16 -0
- data/bitbucket-pipelines.yml +27 -0
- data/lib/pixelpay_sdk/assets/countries.json +247 -0
- data/lib/pixelpay_sdk/assets/formats.json +982 -0
- data/lib/pixelpay_sdk/assets/states.json +3944 -0
- data/lib/pixelpay_sdk/base/Helpers.rb +92 -0
- data/lib/pixelpay_sdk/base/RequestBehaviour.rb +31 -0
- data/lib/pixelpay_sdk/base/Response.rb +78 -0
- data/lib/pixelpay_sdk/base/ServiceBehaviour.rb +237 -0
- data/lib/pixelpay_sdk/entities/CardResult.rb +79 -0
- data/lib/pixelpay_sdk/entities/TransactionResult.rb +104 -0
- data/lib/pixelpay_sdk/exceptions/InvalidCredentialsException.rb +6 -0
- data/lib/pixelpay_sdk/exceptions/InvalidTransactionTypeException.rb +6 -0
- data/lib/pixelpay_sdk/models/Billing.rb +27 -0
- data/lib/pixelpay_sdk/models/Card.rb +36 -0
- data/lib/pixelpay_sdk/models/Item.rb +36 -0
- data/lib/pixelpay_sdk/models/Order.rb +93 -0
- data/lib/pixelpay_sdk/models/Settings.rb +93 -0
- data/lib/pixelpay_sdk/request/AuthTransaction.rb +7 -0
- data/lib/pixelpay_sdk/request/CaptureTransaction.rb +19 -0
- data/lib/pixelpay_sdk/request/CardTokenization.rb +97 -0
- data/lib/pixelpay_sdk/request/PaymentTransaction.rb +179 -0
- data/lib/pixelpay_sdk/request/SaleTransaction.rb +7 -0
- data/lib/pixelpay_sdk/request/StatusTransaction.rb +16 -0
- data/lib/pixelpay_sdk/request/VoidTransaction.rb +19 -0
- data/lib/pixelpay_sdk/resources/Environment.rb +9 -0
- data/lib/pixelpay_sdk/resources/Locations.rb +44 -0
- data/lib/pixelpay_sdk/responses/ErrorResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/FailureResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/InputErrorResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/NetworkFailureResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/NoAccessResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/NotFoundResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/PayloadResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/PaymentDeclinedResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/PreconditionalResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/SuccessResponse.rb +8 -0
- data/lib/pixelpay_sdk/responses/TimeoutResponse.rb +8 -0
- data/lib/pixelpay_sdk/services/Tokenization.rb +65 -0
- data/lib/pixelpay_sdk/services/Transaction.rb +108 -0
- data/lib/pixelpay_sdk/version.rb +5 -0
- data/lib/pixelpay_sdk.rb +20 -0
- data/pixelpay_sdk.gemspec +38 -0
- data/sig/pixelpay_sdk.rbs +4 -0
- metadata +97 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Item represents the item information for a request.
|
4
|
+
class Item
|
5
|
+
attr_accessor :code, :title, :price, :qty, :tax, :total
|
6
|
+
|
7
|
+
# Initialize model
|
8
|
+
def initialize
|
9
|
+
# Item identifier code or UPC/EAN
|
10
|
+
@code = nil
|
11
|
+
|
12
|
+
# Item product title
|
13
|
+
@title = nil
|
14
|
+
|
15
|
+
# Item per unit price
|
16
|
+
@price = 0.00
|
17
|
+
|
18
|
+
# Item quantity
|
19
|
+
@qty = 1
|
20
|
+
|
21
|
+
# Item tax amount per unit
|
22
|
+
@tax = 0.00
|
23
|
+
|
24
|
+
# Item total value
|
25
|
+
@total = 0.00
|
26
|
+
end
|
27
|
+
|
28
|
+
# Totalize item price by quantity.
|
29
|
+
# Returns:
|
30
|
+
# Item: self.
|
31
|
+
def totalize
|
32
|
+
@total = @price * @qty
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base/Helpers"
|
4
|
+
|
5
|
+
# Order represents the order information for a request.
|
6
|
+
class Order
|
7
|
+
attr_accessor :id, :currency, :amount, :tax_amount, :shipping_amount, :content, :extras, :note,
|
8
|
+
:callback_url, :customer_name, :customer_email
|
9
|
+
|
10
|
+
# Initialize model
|
11
|
+
def initialize
|
12
|
+
# Order ID
|
13
|
+
@id = nil
|
14
|
+
|
15
|
+
# Order currency code alpha-3
|
16
|
+
@currency = nil
|
17
|
+
|
18
|
+
# Order total amount
|
19
|
+
@amount = 0.00
|
20
|
+
|
21
|
+
# Order total tax amount
|
22
|
+
@tax_amount = 0.00
|
23
|
+
|
24
|
+
# Order total shipping amount
|
25
|
+
@shipping_amount = 0.00
|
26
|
+
|
27
|
+
# Order summary of items or products
|
28
|
+
@content = []
|
29
|
+
|
30
|
+
# Order extra properties
|
31
|
+
@extras = {}
|
32
|
+
|
33
|
+
# Order note or aditional instructions
|
34
|
+
@note = nil
|
35
|
+
|
36
|
+
# Order calback webhook URL
|
37
|
+
@callback_url = nil
|
38
|
+
|
39
|
+
# Order customer name
|
40
|
+
@customer_name = nil
|
41
|
+
|
42
|
+
# Order customer email
|
43
|
+
@customer_email = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add item to content list of products/items of the order.
|
47
|
+
# Args:
|
48
|
+
# item (Item): model Item.
|
49
|
+
# Returns:
|
50
|
+
# Order: self.
|
51
|
+
def add_item(item)
|
52
|
+
begin
|
53
|
+
Helpers.verify_type(TypeError, Item, item.instance_of?(Item))
|
54
|
+
|
55
|
+
@content.append(item)
|
56
|
+
totalize
|
57
|
+
rescue StandardError => e
|
58
|
+
warn("An exception occurred: #{e.message}")
|
59
|
+
end
|
60
|
+
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
# Add extra property to order.
|
65
|
+
# Args:
|
66
|
+
# key (string): represents the id of the extra.
|
67
|
+
# value (any): represents the content of the extra.
|
68
|
+
# Returns:
|
69
|
+
# Order: self.
|
70
|
+
def add_extra(key, value)
|
71
|
+
@extras[key] = value.to_s if key.to_s != "" && value.to_s != ""
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# Totalize order amounts and items.
|
77
|
+
# Returns:
|
78
|
+
# Order: self.
|
79
|
+
def totalize
|
80
|
+
if @content.length.positive?
|
81
|
+
@amount = 0.00
|
82
|
+
@tax_amount = 0.00
|
83
|
+
|
84
|
+
@content.each do |item|
|
85
|
+
item.totalize
|
86
|
+
@amount += item.total
|
87
|
+
@tax_amount += item.tax * item.qty
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
self
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../resources/Environment"
|
4
|
+
# Settings represents the settings information for a request.
|
5
|
+
class Settings
|
6
|
+
attr_accessor :auth_key, :auth_hash, :auth_user, :endpoint, :environment, :lang
|
7
|
+
|
8
|
+
# Initialize model
|
9
|
+
def initialize
|
10
|
+
# Merchant API auth key
|
11
|
+
@auth_key = nil
|
12
|
+
|
13
|
+
# Merchant API auth hash (MD5 of secret key)
|
14
|
+
@auth_hash = nil
|
15
|
+
|
16
|
+
# Merchant API platform auth user (SHA-512 of user email)
|
17
|
+
@auth_user = nil
|
18
|
+
|
19
|
+
# Merchant API endpoint URL
|
20
|
+
@endpoint = "https://pixelpay.app"
|
21
|
+
|
22
|
+
# Merchant API environment
|
23
|
+
@environment = nil
|
24
|
+
|
25
|
+
# Settings response messages language
|
26
|
+
@lang = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# Setup API endpoint URL.
|
30
|
+
# Args:
|
31
|
+
# endpoint (string): new endpoint URL.
|
32
|
+
# Returns:
|
33
|
+
# Settings: self.
|
34
|
+
def setup_endpoint(endpoint)
|
35
|
+
@endpoint = endpoint.to_s
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Setup API Credentials.
|
41
|
+
# Args:
|
42
|
+
# key (string): represents the merchant model key ID.
|
43
|
+
# hash (string): represents the merchant model secret key.
|
44
|
+
# Returns:
|
45
|
+
# Settings: self.
|
46
|
+
def setup_credentials(key, hash)
|
47
|
+
@auth_key = key.to_s
|
48
|
+
@auth_hash = hash.to_s
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Setup API platform user.
|
54
|
+
# Args:
|
55
|
+
# hash (string): represents the merchant user's email.
|
56
|
+
# Returns:
|
57
|
+
# Settings: self.
|
58
|
+
def setup_platform_user(hash)
|
59
|
+
@auth_user = hash.to_s
|
60
|
+
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
# Setup API platform environment.
|
65
|
+
# Args:
|
66
|
+
# env (string): new environment.
|
67
|
+
# Returns:
|
68
|
+
# Settings: self.
|
69
|
+
def setup_environment(env)
|
70
|
+
@environment = env.to_s
|
71
|
+
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
# Setup defaults to Sandbox credentials.
|
76
|
+
def setup_sandbox
|
77
|
+
@endpoint = "https://pixel-pay.com"
|
78
|
+
@auth_key = "1234567890"
|
79
|
+
@auth_hash = Helpers.hash("MD5", "@s4ndb0x-abcd-1234-n1l4-p1x3l")
|
80
|
+
@environment = Environment::SANDBOX
|
81
|
+
end
|
82
|
+
|
83
|
+
# Setup response messages language.
|
84
|
+
# Args:
|
85
|
+
# lang (string): represents the language to be used.
|
86
|
+
# Returns:
|
87
|
+
# Settings: self.
|
88
|
+
def setup_language(lang)
|
89
|
+
@lang = lang.to_s
|
90
|
+
|
91
|
+
self
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base/RequestBehaviour"
|
4
|
+
|
5
|
+
# CaptureTransaction defines a capture transaction request.
|
6
|
+
class CaptureTransaction < RequestBehaviour
|
7
|
+
attr_accessor :payment_uuid, :transaction_approved_amount
|
8
|
+
|
9
|
+
# Initialize request.
|
10
|
+
def initialize
|
11
|
+
super()
|
12
|
+
|
13
|
+
# Payment UUID
|
14
|
+
@payment_uuid = nil
|
15
|
+
|
16
|
+
# The total amount to capture, equal to or less than the authorized amount.
|
17
|
+
@transaction_approved_amount = nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base/Helpers"
|
4
|
+
require_relative "../base/RequestBehaviour"
|
5
|
+
|
6
|
+
# CardTokenization defines a card tokenization request.
|
7
|
+
class CardTokenization < RequestBehaviour
|
8
|
+
attr_accessor :number, :cvv2, :expire_month, :expire_year, :customer,
|
9
|
+
:cardholder, :address, :country, :state, :city, :zip, :phone, :email
|
10
|
+
|
11
|
+
# Initialize request.
|
12
|
+
def initialize
|
13
|
+
super()
|
14
|
+
|
15
|
+
# Card number or PAN
|
16
|
+
@number = nil
|
17
|
+
|
18
|
+
# Card security code
|
19
|
+
@cvv2 = nil
|
20
|
+
|
21
|
+
# Card expire month date (MM)
|
22
|
+
@expire_month = nil
|
23
|
+
|
24
|
+
# Card expire year date (YYYY)
|
25
|
+
@expire_year = nil
|
26
|
+
|
27
|
+
# Tokenized customer identifier (C-* format)
|
28
|
+
@customer = nil
|
29
|
+
|
30
|
+
# Cardholder name
|
31
|
+
@cardholder = nil
|
32
|
+
|
33
|
+
# Customer billing address
|
34
|
+
@address = nil
|
35
|
+
|
36
|
+
# Customer billing country alpha-2 code (ISO 3166-1)
|
37
|
+
@country = nil
|
38
|
+
|
39
|
+
# Customer billing state alpha code (ISO 3166-2)
|
40
|
+
@state = nil
|
41
|
+
|
42
|
+
# Customer billing city
|
43
|
+
@city = nil
|
44
|
+
|
45
|
+
# Customer billing postal code
|
46
|
+
@zip = nil
|
47
|
+
|
48
|
+
# Customer billing phone
|
49
|
+
@phone = nil
|
50
|
+
|
51
|
+
# Customer email
|
52
|
+
@email = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# Associate and mapping Card model properties to transaction.
|
56
|
+
# Args:
|
57
|
+
# card (Card): input Card.
|
58
|
+
# Returns:
|
59
|
+
# CardTokenization: self.
|
60
|
+
def set_card(card)
|
61
|
+
begin
|
62
|
+
Helpers.verify_type(TypeError, Card, card.instance_of?(Card))
|
63
|
+
|
64
|
+
@number = Helpers.trim_value(card.number)
|
65
|
+
@cvv2 = card.cvv2
|
66
|
+
@expire_month = format("%02d", card.expire_month)
|
67
|
+
@expire_year = card.expire_year.to_s
|
68
|
+
@cardholder = Helpers.trim_value(card.cardholder)
|
69
|
+
rescue StandardError => e
|
70
|
+
warn("An exception occurred: #{e.message}")
|
71
|
+
end
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# Associate and mapping Billing model properties to transaction.
|
77
|
+
# Args:
|
78
|
+
# billing (Billing): input Billing.
|
79
|
+
# Returns:
|
80
|
+
# CardTokenization: self.
|
81
|
+
def set_billing(billing)
|
82
|
+
begin
|
83
|
+
Helpers.verify_type(TypeError, Billing, billing.instance_of?(Billing))
|
84
|
+
|
85
|
+
@address = Helpers.trim_value(billing.address)
|
86
|
+
@country = billing.country
|
87
|
+
@state = billing.state
|
88
|
+
@city = Helpers.trim_value(billing.city)
|
89
|
+
@zip = billing.zip
|
90
|
+
@phone = billing.phone
|
91
|
+
rescue StandardError => e
|
92
|
+
warn("An exception occurred: #{e.message}")
|
93
|
+
end
|
94
|
+
|
95
|
+
self
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base/Helpers"
|
4
|
+
require_relative "../base/RequestBehaviour"
|
5
|
+
|
6
|
+
# PaymentTransaction defines the structure for a payment transaction request.
|
7
|
+
class PaymentTransaction < RequestBehaviour
|
8
|
+
attr_accessor :payment_uuid, :card_token, :card_number, :card_cvv, :card_expire, :card_holder, :billing_address,
|
9
|
+
:billing_country, :billing_state, :billing_city, :billing_zip, :billing_phone, :customer_name,
|
10
|
+
:customer_email, :order_id, :order_currency, :order_amount, :order_tax_amount, :order_shipping_amount,
|
11
|
+
:order_content, :order_extras, :order_note, :order_callback, :authentication_request,
|
12
|
+
:authentication_identifier
|
13
|
+
|
14
|
+
# Initialize request.
|
15
|
+
def initialize
|
16
|
+
super()
|
17
|
+
|
18
|
+
# Payment UUID
|
19
|
+
@payment_uuid = nil
|
20
|
+
|
21
|
+
# Tokenized card identifier (T-* format)
|
22
|
+
@card_token = nil
|
23
|
+
|
24
|
+
# Card number or PAN
|
25
|
+
@card_number = nil
|
26
|
+
|
27
|
+
# Card security code
|
28
|
+
@card_cvv = nil
|
29
|
+
|
30
|
+
# Card expire year/month date (YYMM)
|
31
|
+
@card_expire = nil
|
32
|
+
|
33
|
+
# Cardholder name
|
34
|
+
@card_holder = nil
|
35
|
+
|
36
|
+
# Customer billing address
|
37
|
+
@billing_address = nil
|
38
|
+
|
39
|
+
# Customer billing country alpha-2 code (ISO 3166-1)
|
40
|
+
@billing_country = nil
|
41
|
+
|
42
|
+
# Customer billing state alpha code (ISO 3166-2)
|
43
|
+
@billing_state = nil
|
44
|
+
|
45
|
+
# Customer billing city
|
46
|
+
@billing_city = nil
|
47
|
+
|
48
|
+
# Customer billing postal code
|
49
|
+
@billing_zip = nil
|
50
|
+
|
51
|
+
# Customer billing phone
|
52
|
+
@billing_phone = nil
|
53
|
+
|
54
|
+
# Order customer name
|
55
|
+
@customer_name = nil
|
56
|
+
|
57
|
+
# Order customer email
|
58
|
+
@customer_email = nil
|
59
|
+
|
60
|
+
# Order ID
|
61
|
+
@order_id = nil
|
62
|
+
|
63
|
+
# Order currency code alpha-3
|
64
|
+
@order_currency = nil
|
65
|
+
|
66
|
+
# Order total amount
|
67
|
+
@order_amount = nil
|
68
|
+
|
69
|
+
# Order total tax amount
|
70
|
+
@order_tax_amount = nil
|
71
|
+
|
72
|
+
# Order total shipping amount
|
73
|
+
@order_shipping_amount = nil
|
74
|
+
|
75
|
+
# Order summary of items or products
|
76
|
+
@order_content = []
|
77
|
+
|
78
|
+
# Order extra properties
|
79
|
+
@order_extras = {}
|
80
|
+
|
81
|
+
# Order note or aditional instructions
|
82
|
+
@order_note = nil
|
83
|
+
|
84
|
+
# Order calback webhook URL
|
85
|
+
@order_callback = nil
|
86
|
+
|
87
|
+
# Activate authentication request (3DS/EMV)
|
88
|
+
@authentication_request = false
|
89
|
+
|
90
|
+
# Authentication transaction identifier
|
91
|
+
@authentication_identifier = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
# Associate and mapping Card model properties to transaction.
|
95
|
+
# Args:
|
96
|
+
# card (Card): input Card.
|
97
|
+
# Returns:
|
98
|
+
# PaymentTransaction: self.
|
99
|
+
def set_card(card)
|
100
|
+
begin
|
101
|
+
Helpers.verify_type(TypeError, Card, card.instance_of?(Card))
|
102
|
+
|
103
|
+
@card_number = Helpers.clean_string(card.number)
|
104
|
+
@card_cvv = card.cvv2
|
105
|
+
@card_expire = card.get_expire_format
|
106
|
+
@card_holder = Helpers.trim_value(card.cardholder)
|
107
|
+
rescue StandardError => e
|
108
|
+
warn("An exception occurred: #{e.message}")
|
109
|
+
end
|
110
|
+
|
111
|
+
self
|
112
|
+
end
|
113
|
+
|
114
|
+
# Associate and card token string to transaction.
|
115
|
+
# Args:
|
116
|
+
# card (string): input card token.
|
117
|
+
# Returns:
|
118
|
+
# PaymentTransaction: self.
|
119
|
+
def set_card_token(token)
|
120
|
+
@card_token = token.to_s
|
121
|
+
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
# Associate and mapping Billing model properties to transaction.
|
126
|
+
# Args:
|
127
|
+
# billing (Billing): input Billing.
|
128
|
+
# Returns:
|
129
|
+
# PaymentTransaction: self.
|
130
|
+
def set_billing(billing)
|
131
|
+
begin
|
132
|
+
Helpers.verify_type(TypeError, Billing, billing.instance_of?(Billing))
|
133
|
+
|
134
|
+
@billing_address = Helpers.trim_value(billing.address)
|
135
|
+
@billing_country = billing.country
|
136
|
+
@billing_state = billing.state
|
137
|
+
@billing_city = Helpers.trim_value(billing.city)
|
138
|
+
@billing_zip = billing.zip
|
139
|
+
@billing_phone = billing.phone
|
140
|
+
rescue StandardError => e
|
141
|
+
warn("An exception occurred: #{e.message}")
|
142
|
+
end
|
143
|
+
|
144
|
+
self
|
145
|
+
end
|
146
|
+
|
147
|
+
# Associate and mapping Order model properties to transaction.
|
148
|
+
# Args:
|
149
|
+
# order (Order): input Order.
|
150
|
+
# Returns:
|
151
|
+
# PaymentTransaction: self.
|
152
|
+
def set_order(order)
|
153
|
+
begin
|
154
|
+
Helpers.verify_type(TypeError, Order, order.instance_of?(Order))
|
155
|
+
|
156
|
+
@order_id = order.id
|
157
|
+
@order_currency = order.currency
|
158
|
+
@order_amount = Helpers.parse_amount(order.amount)
|
159
|
+
@order_tax_amount = Helpers.parse_amount(order.tax_amount)
|
160
|
+
@order_shipping_amount = Helpers.parse_amount(order.shipping_amount)
|
161
|
+
@order_content = order.content.empty? ? [] : order.content
|
162
|
+
@order_extras = order.extras.empty? ? {} : order.extras
|
163
|
+
@order_note = Helpers.trim_value(order.note)
|
164
|
+
@order_callback = order.callback_url
|
165
|
+
|
166
|
+
@customer_name = Helpers.trim_value(order.customer_name)
|
167
|
+
@customer_email = order.customer_email
|
168
|
+
rescue StandardError => e
|
169
|
+
warn("An exception occurred: #{e.message}")
|
170
|
+
end
|
171
|
+
|
172
|
+
self
|
173
|
+
end
|
174
|
+
|
175
|
+
# Enable 3DS/EMV authentication request.
|
176
|
+
def with_authentication_request
|
177
|
+
@authentication_request = true
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base/RequestBehaviour"
|
4
|
+
|
5
|
+
# StatusTransaction defines a status transaction request.
|
6
|
+
class StatusTransaction < RequestBehaviour
|
7
|
+
attr_accessor :payment_uuid
|
8
|
+
|
9
|
+
# Initialize request.
|
10
|
+
def initialize
|
11
|
+
super()
|
12
|
+
|
13
|
+
# Payment UUID
|
14
|
+
@payment_uuid = nil
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base/RequestBehaviour"
|
4
|
+
|
5
|
+
# VoidTransaction defines a void transaction request.
|
6
|
+
class VoidTransaction < RequestBehaviour
|
7
|
+
attr_accessor :payment_uuid, :void_reason
|
8
|
+
|
9
|
+
# Initialize request.
|
10
|
+
def initialize
|
11
|
+
super()
|
12
|
+
|
13
|
+
# Payment UUID
|
14
|
+
@payment_uuid = nil
|
15
|
+
|
16
|
+
# Reason for void the order
|
17
|
+
@void_reason = nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
# Utility class.
|
6
|
+
class Locations
|
7
|
+
CURRENT_DIR = File.dirname(__FILE__).freeze
|
8
|
+
|
9
|
+
# Returns a list of countries.
|
10
|
+
# Returns:
|
11
|
+
# hash: hash with available countries.
|
12
|
+
def self.countries_list
|
13
|
+
countries_path = File.join(CURRENT_DIR, "..", "assets", "countries.json")
|
14
|
+
countries_file = File.read(countries_path)
|
15
|
+
|
16
|
+
JSON.parse(countries_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get states list by country ISO code.
|
20
|
+
# Args:
|
21
|
+
# country_code (string): input country code.
|
22
|
+
# Returns:
|
23
|
+
# hash: hash with available states if country_code exists, otherwise an empty hash.
|
24
|
+
def self.states_list(country_code)
|
25
|
+
states_path = File.join(CURRENT_DIR, "..", "assets", "states.json")
|
26
|
+
states_file = File.read(states_path)
|
27
|
+
states_hash = JSON.parse(states_file)
|
28
|
+
|
29
|
+
states_hash.key?(country_code.to_s) ? states_hash[country_code.to_s] : {}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get phone and zip formats list by country ISO code.
|
33
|
+
# Args:
|
34
|
+
# country_code (string): input country code.
|
35
|
+
# Returns:
|
36
|
+
# hash: hash with format data if country_code exists, otherwise an empty hash.
|
37
|
+
def self.formats_list(country_code)
|
38
|
+
formats_path = File.join(CURRENT_DIR, "..", "assets", "formats.json")
|
39
|
+
formats_file = File.read(formats_path)
|
40
|
+
formats_hash = JSON.parse(formats_file)
|
41
|
+
|
42
|
+
formats_hash.key?(country_code.to_s) ? formats_hash[country_code.to_s] : {}
|
43
|
+
end
|
44
|
+
end
|