Class: Sanwo::Client
- Inherits:
-
Object
- Object
- Sanwo::Client
- Defined in:
- lib/sanwo/client.rb
Overview
Server-side HTML generator for Sanwo checkout.
This class does NOT make any HTTP requests. It produces front-end markup that delegates to the Sanwo embed script loaded from the CDN.
Constant Summary collapse
- CDN_URL =
"https://cdn.jsdelivr.net/npm/@sanwohq/embed/dist/sanwo.global.js"
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#template_url ⇒ Object
readonly
Returns the value of attribute template_url.
Instance Method Summary collapse
-
#config ⇒ Hash
Return the current configuration as a plain hash.
-
#initialize(provider:, public_key:, currency: "NGN", debug: false, template_url: nil, template: nil) ⇒ Client
constructor
A new instance of Client.
-
#render_checkout(amount:, email:, description: nil, reference: nil, currency: nil, button_text: "Pay Now", button_class: "sanwo-button", first_name: nil, last_name: nil, phone: nil, callback: nil) ⇒ String
Render a complete checkout button with inline JavaScript.
-
#render_custom_amount(email: nil, currency: nil, button_text: "Pay Now", placeholder: "Enter amount", min_amount: nil, max_amount: nil, description: nil, first_name: nil, last_name: nil, phone: nil, callback: nil) ⇒ String
Render a custom-amount checkout widget.
-
#render_script ⇒ String
Return a
Returns a new instance of Client.
24 25 26 27 28 29 30 31 32 33 34 35 36 37
# File 'lib/sanwo/client.rb', line 24 def initialize(provider:, public_key:, currency: "NGN", debug: false, template_url: nil, template: nil) raise ArgumentError, "public_key is required" if public_key.nil? || public_key.to_s.strip.empty? @provider = Providers.resolve(provider) @public_key = public_key @currency = currency @debug = debug @template_url = template_url @template = template if @provider == Providers::CUSTOM && @template.nil? && @template_url.nil? raise ArgumentError, 'Custom provider requires a "template" or "template_url"' end end