Class: Solidgate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/solidgate/client.rb

Overview

HTTP client for interacting with the Solidgate API

Constant Summary collapse

IV_LENGTH =
16
KEY_LENGTH =
32

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = Solidgate.configuration) ⇒ Client

Returns a new instance of Client.



19
20
21
22
# File 'lib/solidgate/client.rb', line 19

def initialize(options = Solidgate.configuration)
  @config = build_config(options)
  @config.validate!
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/solidgate/client.rb', line 14

def config
  @config
end

Instance Method Details

#capture_payment(payment_id, params = {}) ⇒ Hash

Capture a payment

Parameters:

  • payment_id (String)

    payment ID

  • params (Hash) (defaults to: {})

    capture parameters (optional)

Returns:

  • (Hash)

    capture response



45
46
47
# File 'lib/solidgate/client.rb', line 45

def capture_payment(payment_id, params = {})
  post("/v1/charge/#{payment_id}/capture", params)
end

#create_payment(params) ⇒ Hash

Create a new payment

Parameters:

  • params (Hash)

    payment parameters

Returns:

  • (Hash)

    payment response



28
29
30
# File 'lib/solidgate/client.rb', line 28

def create_payment(params)
  post("/v1/charge", params)
end

#create_price(product_id, params) ⇒ Object



104
105
106
# File 'lib/solidgate/client.rb', line 104

def create_price(product_id, params)
  post("/api/v1/products/#{product_id}/prices", params)
end

#create_product(params) ⇒ Object



100
101
102
# File 'lib/solidgate/client.rb', line 100

def create_product(params)
  post("/api/v1/products", params)
end

#create_subscription(params) ⇒ Hash

Create a subscription

Parameters:

  • params (Hash)

    subscription parameters

Returns:

  • (Hash)

    subscription response



78
79
80
# File 'lib/solidgate/client.rb', line 78

def create_subscription(params)
  post("/v1/subscription", params)
end

#generate_intent(params) ⇒ Object



116
117
118
# File 'lib/solidgate/client.rb', line 116

def generate_intent(params)
  encrypt_payload(params)
end

#generate_signature(json_string, public_key: config.public_key, private_key: config.private_key) ⇒ Object



120
121
122
123
124
125
# File 'lib/solidgate/client.rb', line 120

def generate_signature(json_string, public_key: config.public_key, private_key: config.private_key)
  digest = OpenSSL::Digest.new('sha512')
  instance = OpenSSL::HMAC.new(private_key, digest)
  instance.update(public_key + json_string + public_key)
  Base64.strict_encode64(instance.hexdigest)
end

#get_payment(payment_id) ⇒ Hash

Get payment status

Parameters:

  • payment_id (String)

    payment ID

Returns:

  • (Hash)

    payment details



36
37
38
# File 'lib/solidgate/client.rb', line 36

def get_payment(payment_id)
  get("/v1/charge/#{payment_id}")
end

#product_prices(product_id) ⇒ Object



112
113
114
# File 'lib/solidgate/client.rb', line 112

def product_prices(product_id)
  get("/api/v1/products/#{product_id}/prices")
end

#productsObject



108
109
110
# File 'lib/solidgate/client.rb', line 108

def products
  get("/api/v1/products")
end

#refund_payment(payment_id, params = {}) ⇒ Hash

Refund a payment

Parameters:

  • payment_id (String)

    payment ID

  • params (Hash) (defaults to: {})

    refund parameters

Returns:

  • (Hash)

    refund response



62
63
64
# File 'lib/solidgate/client.rb', line 62

def refund_payment(payment_id, params = {})
  post("/v1/charge/#{payment_id}/refund", params)
end

#settle_payment(params = {}) ⇒ Hash

Settle a payment

Parameters:

  • params (Hash) (defaults to: {})

    settlement parameters

Returns:

  • (Hash)

    settlement response



70
71
72
# File 'lib/solidgate/client.rb', line 70

def settle_payment(params = {})
  conifg.api_url
end

#subscription_status(subscription_id) ⇒ Hash

Get subscription details

Parameters:

  • subscription_id (String)

    subscription ID

Returns:

  • (Hash)

    subscription details



86
87
88
# File 'lib/solidgate/client.rb', line 86

def subscription_status(subscription_id)
  post("/api/v1/subscription/status", { subscription_id: subscription_id })
end

#switch_subscription_product(params) ⇒ Hash

Update subscription product

params = { subscription_id: “sub_12345”, new_product_id: “prod_67890” } new product_id is the Solidgate ID of the product to switch to

Parameters:

  • params (Hash)

    subscription update parameters

Returns:

  • (Hash)

    update response



96
97
98
# File 'lib/solidgate/client.rb', line 96

def switch_subscription_product(params)
  post("/api/v1/subscription/switch-subscription-product", params)
end

#void_payment(payment_id) ⇒ Hash

Void a payment

Parameters:

  • payment_id (String)

    payment ID

Returns:

  • (Hash)

    void response



53
54
55
# File 'lib/solidgate/client.rb', line 53

def void_payment(payment_id)
  post("/v1/charge/#{payment_id}/void")
end