Class: Sanwo::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#currency ⇒ Object (readonly)

Returns the value of attribute currency.



15
16
17
# File 'lib/sanwo/client.rb', line 15

def currency
  @currency
end

#debug ⇒ Object (readonly)

Returns the value of attribute debug.



15
16
17
# File 'lib/sanwo/client.rb', line 15

def debug
  @debug
end

#provider ⇒ Object (readonly)

Returns the value of attribute provider.



15
16
17
# File 'lib/sanwo/client.rb', line 15

def provider
  @provider
end

#public_key ⇒ Object (readonly)

Returns the value of attribute public_key.



15
16
17
# File 'lib/sanwo/client.rb', line 15

def public_key
  @public_key
end

#template ⇒ Object (readonly)

Returns the value of attribute template.



15
16
17
# File 'lib/sanwo/client.rb', line 15

def template
  @template
end

#template_url ⇒ Object (readonly)

Returns the value of attribute template_url.



15
16
17
# File 'lib/sanwo/client.rb', line 15

def template_url
  @template_url
end

Instance Method Details

#config ⇒ Hash

Return the current configuration as a plain hash.

Returns:

  • (Hash)


255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/sanwo/client.rb', line 255

def config
  cfg = {
    provider: @provider,
    public_key: @public_key,
    currency: @currency,
    debug: @debug,
    script_url: CDN_URL,
  }
  cfg[:template_url] = @template_url if @template_url
  cfg[:template]     = @template     if @template
  cfg
end

#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.

The returned HTML contains a

#render_script ⇒ String

Return a