Class: Solidgate::Client
- Inherits:
-
Object
- Object
- Solidgate::Client
- Defined in:
- lib/solidgate/client.rb
Overview
HTTP client for interacting with the Solidgate API. Provides methods for payment processing, subscription management, product management, and payment intent generation.
Constant Summary collapse
- IV_LENGTH =
Length of initialization vector for AES encryption (in bytes)
16- KEY_LENGTH =
Length of encryption key for AES-256 encryption (in bytes)
32
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#alt_refund(params) ⇒ Hash
Creates a refund for an alternative transaction (paypal, bizum, others).
-
#cancel_subscription(params) ⇒ Hash
Cancels an active subscription.
-
#capture_payment(payment_id, params = {}) ⇒ Hash
Captures a previously authorized payment.
-
#create_payment(params) ⇒ Hash
Creates a new payment charge.
-
#create_price(product_id, params) ⇒ Hash
Creates a new price for an existing product.
-
#create_product(params) ⇒ Hash
Creates a new product in the Solidgate catalog.
-
#create_subscription(params) ⇒ Hash
Creates a new recurring subscription.
-
#create_subscription_pause(subscription_id, params) ⇒ Hash
Creates a pause schedule for a subscription.
-
#delete_subscription_pause(subscription_id) ⇒ Hash
Deletes/cancels a pending pause schedule for a subscription.
-
#generate_intent(params) ⇒ String
Generates an encrypted payment intent for client-side payment form rendering.
-
#generate_signature(json_string, public_key: config.public_key, private_key: config.private_key) ⇒ String
Generates an HMAC-SHA512 signature for API request authentication.
-
#get_payment(payment_id) ⇒ Hash
Retrieves payment details and current status.
-
#initialize(options = Solidgate.configuration) ⇒ Client
constructor
Initializes a new Solidgate API client.
- #make_apm_recurring(params) ⇒ Object
- #make_card_recurring(params) ⇒ Object
-
#order_status(params) ⇒ Hash
Retrieves order status from Solidgate pay domain.
-
#product_prices(product_id) ⇒ Hash
Retrieves all prices for a specific product.
-
#products ⇒ Hash
Retrieves all products from the Solidgate catalog.
-
#refund(params) ⇒ Hash
Creates a refund for a transaction.
-
#refund_payment(payment_id, params = {}) ⇒ Hash
Refunds a captured/settled payment.
-
#restore_subscription(params) ⇒ Hash
Restores a previously cancelled subscription.
-
#settle_payment(params = {}) ⇒ String
Settles a payment for final processing.
-
#subscription_status(subscription_id) ⇒ Hash
Retrieves the current status and details of a subscription.
-
#switch_subscription_product(params) ⇒ Hash
Switches a subscription to a different product/plan.
-
#update_product(product_id, params) ⇒ Hash
Updates an existing price for a product.
-
#update_product_price(product_id, price_id, params) ⇒ Hash
Updates an existing price for a product.
-
#update_subscription_pause(subscription_id, params) ⇒ Hash
Updates an existing pause schedule for a subscription.
-
#update_subscription_payment_method(params) ⇒ Hash
Updates the payment method (token) associated with an existing subscription.
-
#void_payment(payment_id) ⇒ Hash
Voids a payment that has not yet been settled.
Constructor Details
#initialize(options = Solidgate.configuration) ⇒ Client
Initializes a new Solidgate API client.
45 46 47 48 |
# File 'lib/solidgate/client.rb', line 45 def initialize( = Solidgate.configuration) @config = build_config() @config.validate! end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
24 25 26 |
# File 'lib/solidgate/client.rb', line 24 def config @config end |
Instance Method Details
#alt_refund(params) ⇒ Hash
Creates a refund for an alternative transaction (paypal, bizum, others).
385 386 387 |
# File 'lib/solidgate/client.rb', line 385 def alt_refund(params) post("/api/v1/refund", body: params, base_url: "https://gate.solidgate.com") end |
#cancel_subscription(params) ⇒ Hash
Cancels an active subscription.
223 224 225 |
# File 'lib/solidgate/client.rb', line 223 def cancel_subscription(params) post("/api/v1/subscription/cancel", body: params) end |
#capture_payment(payment_id, params = {}) ⇒ Hash
Captures a previously authorized payment. Use this to finalize a payment that was created with type ‘auth’.
90 91 92 |
# File 'lib/solidgate/client.rb', line 90 def capture_payment(payment_id, params = {}) post("/v1/charge/#{payment_id}/capture", body: params) end |
#create_payment(params) ⇒ Hash
Creates a new payment charge.
62 63 64 |
# File 'lib/solidgate/client.rb', line 62 def create_payment(params) post("/v1/charge", body: params) end |
#create_price(product_id, params) ⇒ Hash
Creates a new price for an existing product.
250 251 252 |
# File 'lib/solidgate/client.rb', line 250 def create_price(product_id, params) post("/api/v1/products/#{product_id}/prices", body: params) end |
#create_product(params) ⇒ Hash
Creates a new product in the Solidgate catalog.
236 237 238 |
# File 'lib/solidgate/client.rb', line 236 def create_product(params) post("/api/v1/products", body: params) end |
#create_subscription(params) ⇒ Hash
Creates a new recurring subscription.
140 141 142 |
# File 'lib/solidgate/client.rb', line 140 def create_subscription(params) post("/v1/subscription", body: params) end |
#create_subscription_pause(subscription_id, params) ⇒ Hash
Creates a pause schedule for a subscription. The subscription will be paused and resumed at the specified times.
200 201 202 |
# File 'lib/solidgate/client.rb', line 200 def create_subscription_pause(subscription_id, params) post("/api/v1/subscriptions/#{subscription_id}/pause-schedule", body: params) end |
#delete_subscription_pause(subscription_id) ⇒ Hash
Deletes/cancels a pending pause schedule for a subscription.
210 211 212 |
# File 'lib/solidgate/client.rb', line 210 def delete_subscription_pause(subscription_id) delete("/api/v1/subscriptions/#{subscription_id}/pause-schedule") end |
#generate_intent(params) ⇒ String
Generates an encrypted payment intent for client-side payment form rendering. The encrypted intent is used with Solidgate’s JavaScript SDK to securely initialize payment forms without exposing sensitive data.
288 289 290 |
# File 'lib/solidgate/client.rb', line 288 def generate_intent(params) encrypt_payload(params) end |
#generate_signature(json_string, public_key: config.public_key, private_key: config.private_key) ⇒ String
Generates an HMAC-SHA512 signature for API request authentication. The signature is required for all API requests and webhook validation.
334 335 336 337 338 339 |
# File 'lib/solidgate/client.rb', line 334 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
Retrieves payment details and current status.
77 78 79 |
# File 'lib/solidgate/client.rb', line 77 def get_payment(payment_id) get("/v1/charge/#{payment_id}") end |
#make_apm_recurring(params) ⇒ Object
424 425 426 |
# File 'lib/solidgate/client.rb', line 424 def make_apm_recurring(params) post('/api/v1/recurring', body: params, base_url: "https://gate.solidgate.com") end |
#make_card_recurring(params) ⇒ Object
420 421 422 |
# File 'lib/solidgate/client.rb', line 420 def make_card_recurring(params) post('/api/v1/recurring', body: params, base_url: "https://pay.solidgate.com") end |
#order_status(params) ⇒ Hash
Retrieves order status from Solidgate pay domain.
416 417 418 |
# File 'lib/solidgate/client.rb', line 416 def order_status(params) post('/api/v1/status', body: params, base_url: "https://pay.solidgate.com") end |
#product_prices(product_id) ⇒ Hash
Retrieves all prices for a specific product.
268 269 270 |
# File 'lib/solidgate/client.rb', line 268 def product_prices(product_id) get("/api/v1/products/#{product_id}/prices") end |
#products ⇒ Hash
Retrieves all products from the Solidgate catalog.
258 259 260 |
# File 'lib/solidgate/client.rb', line 258 def products get("/api/v1/products") end |
#refund(params) ⇒ Hash
Creates a refund for a transaction.
370 371 372 |
# File 'lib/solidgate/client.rb', line 370 def refund(params) post("/api/v1/refund", body: params, base_url: "https://pay.solidgate.com") end |
#refund_payment(payment_id, params = {}) ⇒ Hash
Refunds a captured/settled payment. Supports both full and partial refunds.
115 116 117 |
# File 'lib/solidgate/client.rb', line 115 def refund_payment(payment_id, params = {}) post("/v1/charge/#{payment_id}/refund", body: params) end |
#restore_subscription(params) ⇒ Hash
Restores a previously cancelled subscription. Use this to reactivate a subscription that was cancelled but is still within the restoration period.
355 356 357 |
# File 'lib/solidgate/client.rb', line 355 def restore_subscription(params) post("/api/v1/subscription/restore", body: params) end |
#settle_payment(params = {}) ⇒ String
Fix this method to properly call the settlement endpoint
Settles a payment for final processing. Note: This method currently has a bug and returns config.api_url instead of making an API call.
126 127 128 |
# File 'lib/solidgate/client.rb', line 126 def settle_payment(params = {}) config.api_url end |
#subscription_status(subscription_id) ⇒ Hash
Retrieves the current status and details of a subscription.
154 155 156 |
# File 'lib/solidgate/client.rb', line 154 def subscription_status(subscription_id) post("/api/v1/subscription/status", body: { subscription_id: subscription_id }) end |
#switch_subscription_product(params) ⇒ Hash
Switches a subscription to a different product/plan. Use this for upgrades, downgrades, or plan changes.
173 174 175 |
# File 'lib/solidgate/client.rb', line 173 def switch_subscription_product(params) post("/api/v1/subscription/switch-subscription-product", body: params) end |
#update_product(product_id, params) ⇒ Hash
Updates an existing price for a product. Use this to modify the amount, currency, or billing interval of a price.
319 320 321 |
# File 'lib/solidgate/client.rb', line 319 def update_product(product_id, params) patch("/api/v1/products/#{product_id}", body: params) end |
#update_product_price(product_id, price_id, params) ⇒ Hash
Updates an existing price for a product. Use this to modify the amount, currency, or billing interval of a price.
304 305 306 |
# File 'lib/solidgate/client.rb', line 304 def update_product_price(product_id, price_id, params) patch("/api/v1/products/#{product_id}/prices/#{price_id}", body: params) end |
#update_subscription_pause(subscription_id, params) ⇒ Hash
Updates an existing pause schedule for a subscription.
186 187 188 |
# File 'lib/solidgate/client.rb', line 186 def update_subscription_pause(subscription_id, params) patch("/api/v1/subscriptions/#{subscription_id}/pause-schedule", body: params) end |
#update_subscription_payment_method(params) ⇒ Hash
Updates the payment method (token) associated with an existing subscription.
402 403 404 |
# File 'lib/solidgate/client.rb', line 402 def update_subscription_payment_method(params) post("/api/v1/subscription/update-token", body: params) end |
#void_payment(payment_id) ⇒ Hash
Voids a payment that has not yet been settled. Voiding cancels the authorization and releases the hold on customer funds.
101 102 103 |
# File 'lib/solidgate/client.rb', line 101 def void_payment(payment_id) post("/v1/charge/#{payment_id}/void") end |