pay 3.0.12 → 3.0.16
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pay might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/models/pay/charge.rb +8 -0
- data/app/models/pay/customer.rb +4 -2
- data/app/models/pay/merchant.rb +3 -2
- data/app/models/pay/payment_method.rb +1 -0
- data/app/views/pay/payments/show.html.erb +2 -2
- data/app/views/pay/user_mailer/receipt.html.erb +1 -1
- data/app/views/pay/user_mailer/refund.html.erb +1 -1
- data/config/currencies/iso.json +2702 -0
- data/lib/pay/currency.rb +74 -0
- data/lib/pay/payment.rb +5 -1
- data/lib/pay/receipts.rb +3 -5
- data/lib/pay/stripe/payment_method.rb +1 -1
- data/lib/pay/version.rb +1 -1
- data/lib/pay.rb +1 -0
- metadata +4 -2
data/lib/pay/currency.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Pay
|
2
|
+
class Currency
|
3
|
+
include ActionView::Helpers::NumberHelper
|
4
|
+
|
5
|
+
attr_reader :attributes
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
@currencies ||= begin
|
9
|
+
path = Engine.root.join("config", "currencies", "iso.json")
|
10
|
+
JSON.parse File.read(path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Takes an amount (in cents) and currency and returns the formatted version for the currency
|
15
|
+
def self.format(amount, currency:, **options)
|
16
|
+
currency ||= :usd
|
17
|
+
new(currency).format_amount(amount, **options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(iso_code)
|
21
|
+
@attributes = self.class.all[iso_code.to_s.downcase]
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_amount(amount, **options)
|
25
|
+
number_to_currency(
|
26
|
+
amount.to_i / subunit_to_unit.to_f,
|
27
|
+
{
|
28
|
+
precision: precision,
|
29
|
+
unit: unit,
|
30
|
+
separator: separator,
|
31
|
+
delimiter: delimiter,
|
32
|
+
format: format
|
33
|
+
}.compact.merge(options)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the precision to display
|
38
|
+
#
|
39
|
+
# If 1, returns 0
|
40
|
+
# If 100, returns 2
|
41
|
+
# If 1000, returns 3
|
42
|
+
def precision
|
43
|
+
subunit_to_unit.digits.count - 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def unit
|
47
|
+
attributes["unit"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def separator
|
51
|
+
attributes["separator"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def delimiter
|
55
|
+
attributes["delimiter"]
|
56
|
+
end
|
57
|
+
|
58
|
+
def format
|
59
|
+
attributes["format"]
|
60
|
+
end
|
61
|
+
|
62
|
+
def subunit?
|
63
|
+
subunit.blank?
|
64
|
+
end
|
65
|
+
|
66
|
+
def subunit
|
67
|
+
attributes["subunit"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def subunit_to_unit
|
71
|
+
attributes["subunit_to_unit"]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/pay/payment.rb
CHANGED
@@ -2,7 +2,7 @@ module Pay
|
|
2
2
|
class Payment
|
3
3
|
attr_reader :intent
|
4
4
|
|
5
|
-
delegate :id, :amount, :client_secret, :customer, :status, :confirm, to: :intent
|
5
|
+
delegate :id, :amount, :client_secret, :currency, :customer, :status, :confirm, to: :intent
|
6
6
|
|
7
7
|
def self.from_id(id)
|
8
8
|
intent = id.start_with?("seti_") ? ::Stripe::SetupIntent.retrieve(id) : ::Stripe::PaymentIntent.retrieve(id)
|
@@ -41,6 +41,10 @@ module Pay
|
|
41
41
|
intent.is_a?(::Stripe::SetupIntent)
|
42
42
|
end
|
43
43
|
|
44
|
+
def amount_with_currency
|
45
|
+
Pay::Currency.format(amount, currency: currency)
|
46
|
+
end
|
47
|
+
|
44
48
|
def validate
|
45
49
|
if requires_payment_method?
|
46
50
|
raise Pay::InvalidPaymentMethod.new(self)
|
data/lib/pay/receipts.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Pay
|
2
2
|
module Receipts
|
3
|
-
include ActionView::Helpers::NumberHelper
|
4
|
-
|
5
3
|
def product
|
6
4
|
Pay.application_name
|
7
5
|
end
|
@@ -20,11 +18,11 @@ module Pay
|
|
20
18
|
[I18n.t("pay.receipt.date"), I18n.l(created_at, format: :long)],
|
21
19
|
[I18n.t("pay.receipt.account_billed"), "#{customer.customer_name} (#{customer.email})"],
|
22
20
|
[I18n.t("pay.receipt.product"), product],
|
23
|
-
[I18n.t("pay.receipt.amount"),
|
21
|
+
[I18n.t("pay.receipt.amount"), Pay::Currency.format(amount, currency: currency)],
|
24
22
|
[I18n.t("pay.receipt.charged_to"), charged_to]
|
25
23
|
]
|
26
24
|
line_items << [I18n.t("pay.receipt.additional_info"), customer.owner.extra_billing_info] if customer.owner.extra_billing_info?
|
27
|
-
line_items << [I18n.t("pay.receipt.refunded"),
|
25
|
+
line_items << [I18n.t("pay.receipt.refunded"), Pay::Currency.format(amount_refunded, currency: currency)] if refunded?
|
28
26
|
|
29
27
|
defaults = {
|
30
28
|
id: id,
|
@@ -54,7 +52,7 @@ module Pay
|
|
54
52
|
bill_to += [customer.owner.extra_billing_info] if customer.owner.extra_billing_info?
|
55
53
|
bill_to += [nil, customer.owner.email]
|
56
54
|
|
57
|
-
total =
|
55
|
+
total = Pay::Currency.format(amount, currency: currency)
|
58
56
|
|
59
57
|
line_items = [
|
60
58
|
["<b>#{I18n.t("pay.invoice.product")}</b>", nil, "<b>#{I18n.t("pay.invoice.amount")}</b>"],
|
@@ -18,7 +18,7 @@ module Pay
|
|
18
18
|
default_payment_method_id = pay_customer.customer.invoice_settings.default_payment_method
|
19
19
|
default = (id == default_payment_method_id)
|
20
20
|
|
21
|
-
attributes = extract_attributes(object).merge(default: default)
|
21
|
+
attributes = extract_attributes(object).merge(default: default, stripe_account: stripe_account)
|
22
22
|
|
23
23
|
pay_customer.payment_methods.update_all(default: false) if default
|
24
24
|
pay_payment_method = pay_customer.payment_methods.where(processor_id: object.id).first_or_initialize
|
data/lib/pay/version.rb
CHANGED
data/lib/pay.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Charnes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-09-
|
12
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- app/views/pay/user_mailer/receipt.html.erb
|
120
120
|
- app/views/pay/user_mailer/refund.html.erb
|
121
121
|
- app/views/pay/user_mailer/subscription_renewing.html.erb
|
122
|
+
- config/currencies/iso.json
|
122
123
|
- config/locales/en.yml
|
123
124
|
- config/routes.rb
|
124
125
|
- db/migrate/1_create_pay_tables.rb
|
@@ -149,6 +150,7 @@ files:
|
|
149
150
|
- lib/pay/braintree/webhooks/subscription_trial_ended.rb
|
150
151
|
- lib/pay/braintree/webhooks/subscription_went_active.rb
|
151
152
|
- lib/pay/braintree/webhooks/subscription_went_past_due.rb
|
153
|
+
- lib/pay/currency.rb
|
152
154
|
- lib/pay/engine.rb
|
153
155
|
- lib/pay/env.rb
|
154
156
|
- lib/pay/errors.rb
|