Class: PaynowQR::Generator
- Inherits:
-
Object
- Object
- PaynowQR::Generator
- Defined in:
- lib/paynow_qr/generator.rb
Overview
Builds an EMVCo-compliant PayNow (SGQR) payload string.
Constant Summary collapse
- PROXY_TYPES =
{ mobile: "0", uen: "2" }.freeze
- DEFAULT_COMPANY =
"NA"- CURRENCY_SGD =
"702"- COUNTRY_SG =
"SG"- CITY_SINGAPORE =
"Singapore"- MCC_UNUSED =
"0000"- FIELD_LIMITS =
EMVCo per-field maximum lengths (counted in bytes to match TLV encoding).
{ company: 25, # EMVCo §4.11 Merchant Name reference: 25, # EMVCo §4.14.1 Bill Number amount: 13 # EMVCo §4.7 Transaction Amount }.freeze
- UEN_REGEX =
Singapore ACRA UEN formats: business (9 chars), local company (10 chars), other entity (10 chars).
/\A(?:\d{8}[A-Z]|\d{9}[A-Z]|[STR]\d{2}[A-Z]{2}\d{4}[A-Z])\z/- SG_MOBILE_REGEX =
Singapore mobile in E.164 — +65 followed by 8 digits starting with 8 or 9.
/\A\+65[89]\d{7}\z/
Instance Method Summary collapse
-
#initialize(proxy_type:, proxy_value:, amount: nil, editable: false, company: DEFAULT_COMPANY, expiry: nil, reference: nil, strict: false) ⇒ Generator
constructor
A new instance of Generator.
-
#payload ⇒ String
(also: #to_s)
Complete EMVCo QR payload with CRC.
Constructor Details
#initialize(proxy_type:, proxy_value:, amount: nil, editable: false, company: DEFAULT_COMPANY, expiry: nil, reference: nil, strict: false) ⇒ Generator
Returns a new instance of Generator.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/paynow_qr/generator.rb', line 47 def initialize(proxy_type:, proxy_value:, amount: nil, editable: false, company: DEFAULT_COMPANY, expiry: nil, reference: nil, strict: false) @proxy_type = resolve_proxy_type(proxy_type) @proxy_value = require_present(proxy_value, :proxy_value).strip @amount = amount @editable = editable ? true : false @company = (company.to_s.strip.empty? ? DEFAULT_COMPANY : company.to_s.strip) @expiry = normalize_expiry(expiry) @reference = normalize_reference(reference) @amount_str = amount.nil? ? nil : format_amount(amount) @strict = strict ? true : false validate_lengths! validate_strict! if @strict end |