taiwan_payments 0.1.0
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/CHANGELOG.md +24 -0
- data/LICENSE.txt +21 -0
- data/README.ja.md +293 -0
- data/README.md +291 -0
- data/README.zh-TW.md +293 -0
- data/docs/ecpay-invoices.md +202 -0
- data/docs/ecpay-payments.md +191 -0
- data/docs/glossary/concepts.ja.md +33 -0
- data/docs/glossary/concepts.md +34 -0
- data/docs/glossary/ecpay-invoice.ja.md +113 -0
- data/docs/glossary/ecpay-invoice.md +114 -0
- data/docs/glossary/ecpay-payment.ja.md +64 -0
- data/docs/glossary/ecpay-payment.md +65 -0
- data/docs/rails.md +184 -0
- data/docs/sandbox-setup.md +104 -0
- data/docs/taiwan-payments-101.ja.md +138 -0
- data/docs/taiwan-payments-101.md +138 -0
- data/docs/taiwan-payments-101.zh-TW.md +138 -0
- data/docs/testing.md +140 -0
- data/docs/webhooks.md +113 -0
- data/exe/taiwan_payments +6 -0
- data/lib/generators/taiwan_payments/install/install_generator.rb +41 -0
- data/lib/generators/taiwan_payments/install/templates/ecpay_controller.rb.tt +26 -0
- data/lib/generators/taiwan_payments/install/templates/initializer.rb.tt +38 -0
- data/lib/taiwan_payments/cli.rb +271 -0
- data/lib/taiwan_payments/configuration.rb +86 -0
- data/lib/taiwan_payments/credentials.rb +27 -0
- data/lib/taiwan_payments/decimal.rb +36 -0
- data/lib/taiwan_payments/ecpay/aes_cipher.rb +36 -0
- data/lib/taiwan_payments/ecpay/check_mac_value.rb +63 -0
- data/lib/taiwan_payments/ecpay/checkout.rb +154 -0
- data/lib/taiwan_payments/ecpay/invoice_client.rb +253 -0
- data/lib/taiwan_payments/ecpay/invoice_mapper.rb +222 -0
- data/lib/taiwan_payments/ecpay/payment_client.rb +188 -0
- data/lib/taiwan_payments/ecpay/payment_methods.rb +40 -0
- data/lib/taiwan_payments/ecpay/payment_notification.rb +127 -0
- data/lib/taiwan_payments/ecpay/response_body.rb +30 -0
- data/lib/taiwan_payments/ecpay/trade_info.rb +68 -0
- data/lib/taiwan_payments/ecpay.rb +19 -0
- data/lib/taiwan_payments/environment.rb +22 -0
- data/lib/taiwan_payments/error_codes/ecpay_invoice.yml +80 -0
- data/lib/taiwan_payments/error_codes/ecpay_payment.yml +59 -0
- data/lib/taiwan_payments/error_codes.rb +23 -0
- data/lib/taiwan_payments/errors.rb +71 -0
- data/lib/taiwan_payments/form_helper.rb +21 -0
- data/lib/taiwan_payments/glossary/concepts.yml +122 -0
- data/lib/taiwan_payments/glossary/ecpay_invoice.yml +523 -0
- data/lib/taiwan_payments/glossary/ecpay_payment.yml +278 -0
- data/lib/taiwan_payments/glossary.rb +106 -0
- data/lib/taiwan_payments/hosted_form.rb +46 -0
- data/lib/taiwan_payments/http_client.rb +62 -0
- data/lib/taiwan_payments/instrumentation.rb +42 -0
- data/lib/taiwan_payments/invoice.rb +235 -0
- data/lib/taiwan_payments/money.rb +32 -0
- data/lib/taiwan_payments/php_compat.rb +39 -0
- data/lib/taiwan_payments/railtie.rb +23 -0
- data/lib/taiwan_payments/redactor.rb +29 -0
- data/lib/taiwan_payments/taipei_time.rb +42 -0
- data/lib/taiwan_payments/tax_id.rb +26 -0
- data/lib/taiwan_payments/testing.rb +152 -0
- data/lib/taiwan_payments/validation.rb +56 -0
- data/lib/taiwan_payments/version.rb +5 -0
- data/lib/taiwan_payments/webhooks.rb +54 -0
- data/lib/taiwan_payments.rb +67 -0
- metadata +118 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TaiwanPayments
|
|
4
|
+
# Controller concern for the endpoints vendors call back.
|
|
5
|
+
#
|
|
6
|
+
# class Webhooks::EcpayController < ApplicationController
|
|
7
|
+
# include TaiwanPayments::Webhooks
|
|
8
|
+
#
|
|
9
|
+
# def payment
|
|
10
|
+
# notification = ecpay_payment_notification
|
|
11
|
+
# Order.find_by!(number: notification.order_no).mark_paid! if notification.paid?
|
|
12
|
+
# render_ecpay_ack
|
|
13
|
+
# end
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# Give callbacks a controller of their own: including this switches CSRF
|
|
17
|
+
# protection off for the whole controller.
|
|
18
|
+
module Webhooks
|
|
19
|
+
extend ActiveSupport::Concern
|
|
20
|
+
|
|
21
|
+
included do
|
|
22
|
+
# Callbacks are posted by the vendor's servers, or by the customer's
|
|
23
|
+
# browser from the vendor's domain, so they can never carry this app's
|
|
24
|
+
# CSRF token. The signature check takes its place. API-only
|
|
25
|
+
# controllers have no CSRF protection to skip.
|
|
26
|
+
skip_forgery_protection if respond_to?(:skip_forgery_protection)
|
|
27
|
+
|
|
28
|
+
rescue_from TaiwanPayments::SignatureError, with: :reject_unverified_callback
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
# @param client [ECPay::PaymentClient] defaults to the configured one
|
|
34
|
+
# @return [ECPay::PaymentNotification] verified against the merchant's keys
|
|
35
|
+
# @raise [SignatureError] answered with HTTP 400 unless the action rescues it
|
|
36
|
+
def ecpay_payment_notification(client = TaiwanPayments.ecpay_payments)
|
|
37
|
+
# request_parameters is the POST body alone. `params` also carries
|
|
38
|
+
# route and query-string values, which ECPay never signed.
|
|
39
|
+
client.notification(request.request_parameters)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# ECPay keeps retrying a callback until it reads exactly this body.
|
|
43
|
+
def render_ecpay_ack
|
|
44
|
+
render plain: ECPay::PaymentNotification::ACK
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def reject_unverified_callback(error)
|
|
48
|
+
# Wrong keys make every callback fail this way, and the vendor's
|
|
49
|
+
# retries are the only other sign of it.
|
|
50
|
+
logger&.warn("[taiwan_payments] rejected a callback: #{error.message_en}")
|
|
51
|
+
head :bad_request
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "openssl"
|
|
5
|
+
require "digest"
|
|
6
|
+
|
|
7
|
+
require_relative "taiwan_payments/version"
|
|
8
|
+
require_relative "taiwan_payments/errors"
|
|
9
|
+
require_relative "taiwan_payments/validation"
|
|
10
|
+
require_relative "taiwan_payments/php_compat"
|
|
11
|
+
require_relative "taiwan_payments/money"
|
|
12
|
+
require_relative "taiwan_payments/decimal"
|
|
13
|
+
require_relative "taiwan_payments/taipei_time"
|
|
14
|
+
require_relative "taiwan_payments/credentials"
|
|
15
|
+
require_relative "taiwan_payments/environment"
|
|
16
|
+
require_relative "taiwan_payments/redactor"
|
|
17
|
+
require_relative "taiwan_payments/instrumentation"
|
|
18
|
+
require_relative "taiwan_payments/http_client"
|
|
19
|
+
require_relative "taiwan_payments/hosted_form"
|
|
20
|
+
require_relative "taiwan_payments/error_codes"
|
|
21
|
+
require_relative "taiwan_payments/tax_id"
|
|
22
|
+
require_relative "taiwan_payments/invoice"
|
|
23
|
+
require_relative "taiwan_payments/ecpay"
|
|
24
|
+
require_relative "taiwan_payments/configuration"
|
|
25
|
+
|
|
26
|
+
# Unit specs load the gem before Rails; spec/taiwan_payments/loading_spec.rb
|
|
27
|
+
# covers both sides of this in subprocesses.
|
|
28
|
+
# :nocov:
|
|
29
|
+
require_relative "taiwan_payments/railtie" if defined?(::Rails::Railtie)
|
|
30
|
+
# :nocov:
|
|
31
|
+
|
|
32
|
+
# Payments and e-invoicing for Taiwan: ECPay (綠界) today, NewebPay (藍新) and
|
|
33
|
+
# ezPay (簡單付) next. See README.md for a quick start.
|
|
34
|
+
module TaiwanPayments
|
|
35
|
+
class << self
|
|
36
|
+
# Language used for Error#message. Vendor messages are Chinese, so English
|
|
37
|
+
# is the default for the audience that cannot read them.
|
|
38
|
+
#
|
|
39
|
+
# @return [Symbol] :en, :zh_tw or :ja
|
|
40
|
+
def locale
|
|
41
|
+
Thread.current[:taiwan_payments_locale] || @locale || :en
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def locale=(value)
|
|
45
|
+
@locale = normalize_locale(value)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def with_locale(value)
|
|
49
|
+
previous = Thread.current[:taiwan_payments_locale]
|
|
50
|
+
Thread.current[:taiwan_payments_locale] = normalize_locale(value)
|
|
51
|
+
yield
|
|
52
|
+
ensure
|
|
53
|
+
Thread.current[:taiwan_payments_locale] = previous
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Accepts whatever an app already has to hand ("zh-TW", :"zh-TW", :zh_tw,
|
|
59
|
+
# "ja-JP", I18n.locale) so callers do not need a mapping table of their own.
|
|
60
|
+
def normalize_locale(value)
|
|
61
|
+
text = value.to_s.downcase
|
|
62
|
+
return :zh_tw if text.start_with?("zh")
|
|
63
|
+
|
|
64
|
+
text.start_with?("ja") ? :ja : :en
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: taiwan_payments
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jay W
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: |
|
|
13
|
+
Take payments and issue e-invoices (電子發票) in Taiwan from Ruby. Supports ECPay
|
|
14
|
+
(綠界) payments and e-invoices, with NewebPay (藍新) and ezPay planned. No runtime
|
|
15
|
+
dependencies, an optional Rails layer, signed test doubles for callbacks, errors
|
|
16
|
+
and documentation in English, Traditional Chinese and Japanese, and crypto verified
|
|
17
|
+
against ECPay's published test vectors.
|
|
18
|
+
email:
|
|
19
|
+
- jay@thedevsquad.com
|
|
20
|
+
executables:
|
|
21
|
+
- taiwan_payments
|
|
22
|
+
extensions: []
|
|
23
|
+
extra_rdoc_files: []
|
|
24
|
+
files:
|
|
25
|
+
- CHANGELOG.md
|
|
26
|
+
- LICENSE.txt
|
|
27
|
+
- README.ja.md
|
|
28
|
+
- README.md
|
|
29
|
+
- README.zh-TW.md
|
|
30
|
+
- docs/ecpay-invoices.md
|
|
31
|
+
- docs/ecpay-payments.md
|
|
32
|
+
- docs/glossary/concepts.ja.md
|
|
33
|
+
- docs/glossary/concepts.md
|
|
34
|
+
- docs/glossary/ecpay-invoice.ja.md
|
|
35
|
+
- docs/glossary/ecpay-invoice.md
|
|
36
|
+
- docs/glossary/ecpay-payment.ja.md
|
|
37
|
+
- docs/glossary/ecpay-payment.md
|
|
38
|
+
- docs/rails.md
|
|
39
|
+
- docs/sandbox-setup.md
|
|
40
|
+
- docs/taiwan-payments-101.ja.md
|
|
41
|
+
- docs/taiwan-payments-101.md
|
|
42
|
+
- docs/taiwan-payments-101.zh-TW.md
|
|
43
|
+
- docs/testing.md
|
|
44
|
+
- docs/webhooks.md
|
|
45
|
+
- exe/taiwan_payments
|
|
46
|
+
- lib/generators/taiwan_payments/install/install_generator.rb
|
|
47
|
+
- lib/generators/taiwan_payments/install/templates/ecpay_controller.rb.tt
|
|
48
|
+
- lib/generators/taiwan_payments/install/templates/initializer.rb.tt
|
|
49
|
+
- lib/taiwan_payments.rb
|
|
50
|
+
- lib/taiwan_payments/cli.rb
|
|
51
|
+
- lib/taiwan_payments/configuration.rb
|
|
52
|
+
- lib/taiwan_payments/credentials.rb
|
|
53
|
+
- lib/taiwan_payments/decimal.rb
|
|
54
|
+
- lib/taiwan_payments/ecpay.rb
|
|
55
|
+
- lib/taiwan_payments/ecpay/aes_cipher.rb
|
|
56
|
+
- lib/taiwan_payments/ecpay/check_mac_value.rb
|
|
57
|
+
- lib/taiwan_payments/ecpay/checkout.rb
|
|
58
|
+
- lib/taiwan_payments/ecpay/invoice_client.rb
|
|
59
|
+
- lib/taiwan_payments/ecpay/invoice_mapper.rb
|
|
60
|
+
- lib/taiwan_payments/ecpay/payment_client.rb
|
|
61
|
+
- lib/taiwan_payments/ecpay/payment_methods.rb
|
|
62
|
+
- lib/taiwan_payments/ecpay/payment_notification.rb
|
|
63
|
+
- lib/taiwan_payments/ecpay/response_body.rb
|
|
64
|
+
- lib/taiwan_payments/ecpay/trade_info.rb
|
|
65
|
+
- lib/taiwan_payments/environment.rb
|
|
66
|
+
- lib/taiwan_payments/error_codes.rb
|
|
67
|
+
- lib/taiwan_payments/error_codes/ecpay_invoice.yml
|
|
68
|
+
- lib/taiwan_payments/error_codes/ecpay_payment.yml
|
|
69
|
+
- lib/taiwan_payments/errors.rb
|
|
70
|
+
- lib/taiwan_payments/form_helper.rb
|
|
71
|
+
- lib/taiwan_payments/glossary.rb
|
|
72
|
+
- lib/taiwan_payments/glossary/concepts.yml
|
|
73
|
+
- lib/taiwan_payments/glossary/ecpay_invoice.yml
|
|
74
|
+
- lib/taiwan_payments/glossary/ecpay_payment.yml
|
|
75
|
+
- lib/taiwan_payments/hosted_form.rb
|
|
76
|
+
- lib/taiwan_payments/http_client.rb
|
|
77
|
+
- lib/taiwan_payments/instrumentation.rb
|
|
78
|
+
- lib/taiwan_payments/invoice.rb
|
|
79
|
+
- lib/taiwan_payments/money.rb
|
|
80
|
+
- lib/taiwan_payments/php_compat.rb
|
|
81
|
+
- lib/taiwan_payments/railtie.rb
|
|
82
|
+
- lib/taiwan_payments/redactor.rb
|
|
83
|
+
- lib/taiwan_payments/taipei_time.rb
|
|
84
|
+
- lib/taiwan_payments/tax_id.rb
|
|
85
|
+
- lib/taiwan_payments/testing.rb
|
|
86
|
+
- lib/taiwan_payments/validation.rb
|
|
87
|
+
- lib/taiwan_payments/version.rb
|
|
88
|
+
- lib/taiwan_payments/webhooks.rb
|
|
89
|
+
homepage: https://github.com/randomizor/taiwan_payments
|
|
90
|
+
licenses:
|
|
91
|
+
- MIT
|
|
92
|
+
metadata:
|
|
93
|
+
homepage_uri: https://github.com/randomizor/taiwan_payments
|
|
94
|
+
source_code_uri: https://github.com/randomizor/taiwan_payments
|
|
95
|
+
changelog_uri: https://github.com/randomizor/taiwan_payments/blob/main/CHANGELOG.md
|
|
96
|
+
documentation_uri: https://github.com/randomizor/taiwan_payments/blob/main/README.md
|
|
97
|
+
bug_tracker_uri: https://github.com/randomizor/taiwan_payments/issues
|
|
98
|
+
funding_uri: https://buymeacoffee.com/randomizor
|
|
99
|
+
rubygems_mfa_required: 'true'
|
|
100
|
+
rdoc_options: []
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '3.2'
|
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
requirements: []
|
|
114
|
+
rubygems_version: 4.0.3
|
|
115
|
+
specification_version: 4
|
|
116
|
+
summary: 'Payments and e-invoices for Taiwan: ECPay (綠界) today, NewebPay and ezPay
|
|
117
|
+
next.'
|
|
118
|
+
test_files: []
|