solidgate-ruby-sdk 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d961fde0b15268aa678aa14a4578f1de1ad1585d3729c4bdc75168760825bc1
4
- data.tar.gz: bf319d42486fed3f868d17994da9041214c89daa63b02d24be45ea9afdd53ac7
3
+ metadata.gz: 7f1670a04649a2c491affa62db248bd7bb08ecb82d3db6df1d132131ee486bf6
4
+ data.tar.gz: 1d611dae1d1e9d8ddb8aa8b74161ccb064b57cddfa0f57c2bc2777916f5d7eb6
5
5
  SHA512:
6
- metadata.gz: 02e23da68d02d2af05bc92880877f671c59c7eb55290e46bb5657207f3c8360fc19c1d31a4df8f0237e9f4fadf381270db3cec098b3ab0df80a1aa04ac21fb31
7
- data.tar.gz: c2fa5f81f3d65fab20906c03f427fd15848962b3052801e6148871b02bfe4068547dcee3c45da97a428d905944094c208febcb9b8ffa2bb4b47e2c3aa4c0b298
6
+ metadata.gz: '08e8fb84413b4e7ad186c4b70c9099764c5d0b7d3b598e12772e07712ebc98890d979b73b7c52a00ed1cb7bb1d833eac20ff85d95e1a1d8f6ddb698a9117fea7'
7
+ data.tar.gz: 6a4cc2aff3ce40534e1eb77b3a3b5d4e95232edc599e348054890a269eeb09659cf7f6f675b61c408cd10fa213dcf570999a46dc9532ab3c09df113df88e11f3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solidgate-ruby-sdk (0.1.9)
4
+ solidgate-ruby-sdk (0.1.10)
5
5
  faraday
6
6
  faraday-multipart
7
7
 
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/solidgate-ruby-sdk.svg)](https://badge.fury.io/rb/solidgate-ruby-sdk)
2
+
1
3
  # Solidgate Ruby SDK
2
4
 
3
5
  A Ruby (unofficial) SDK for integrating with the Solidgate payment gateway API.
@@ -60,7 +60,7 @@ module Solidgate
60
60
  # @raise [AuthenticationError] if API credentials are invalid
61
61
  #
62
62
  def create_payment(params)
63
- post("/v1/charge", params)
63
+ post("/v1/charge", body: params)
64
64
  end
65
65
 
66
66
  # Retrieves payment details and current status.
@@ -88,7 +88,7 @@ module Solidgate
88
88
  # @raise [InvalidRequestError] if payment cannot be captured (wrong status, already captured, etc.)
89
89
  #
90
90
  def capture_payment(payment_id, params = {})
91
- post("/v1/charge/#{payment_id}/capture", params)
91
+ post("/v1/charge/#{payment_id}/capture", body: params)
92
92
  end
93
93
 
94
94
  # Voids a payment that has not yet been settled.
@@ -113,7 +113,7 @@ module Solidgate
113
113
  # @raise [InvalidRequestError] if payment cannot be refunded
114
114
  #
115
115
  def refund_payment(payment_id, params = {})
116
- post("/v1/charge/#{payment_id}/refund", params)
116
+ post("/v1/charge/#{payment_id}/refund", body: params)
117
117
  end
118
118
 
119
119
  # Settles a payment for final processing.
@@ -138,7 +138,7 @@ module Solidgate
138
138
  # @raise [InvalidRequestError] if subscription parameters are invalid
139
139
  #
140
140
  def create_subscription(params)
141
- post("/v1/subscription", params)
141
+ post("/v1/subscription", body: params)
142
142
  end
143
143
 
144
144
  # Retrieves the current status and details of a subscription.
@@ -152,7 +152,7 @@ module Solidgate
152
152
  # @raise [InvalidRequestError] if subscription_id is not found
153
153
  #
154
154
  def subscription_status(subscription_id)
155
- post("/api/v1/subscription/status", { subscription_id: subscription_id })
155
+ post("/api/v1/subscription/status", body: { subscription_id: subscription_id })
156
156
  end
157
157
 
158
158
  # Switches a subscription to a different product/plan.
@@ -171,7 +171,7 @@ module Solidgate
171
171
  # )
172
172
  #
173
173
  def switch_subscription_product(params)
174
- post("/api/v1/subscription/switch-subscription-product", params)
174
+ post("/api/v1/subscription/switch-subscription-product", body: params)
175
175
  end
176
176
 
177
177
  # Updates an existing pause schedule for a subscription.
@@ -184,7 +184,7 @@ module Solidgate
184
184
  # @raise [InvalidRequestError] if subscription has no pause schedule or params are invalid
185
185
  #
186
186
  def update_subscription_pause(subscription_id, params)
187
- patch("/api/v1/subscriptions/#{subscription_id}/pause-schedule", params)
187
+ patch("/api/v1/subscriptions/#{subscription_id}/pause-schedule", body: params)
188
188
  end
189
189
 
190
190
  # Creates a pause schedule for a subscription.
@@ -198,7 +198,7 @@ module Solidgate
198
198
  # @raise [InvalidRequestError] if subscription is invalid or already has a pause schedule
199
199
  #
200
200
  def create_subscription_pause(subscription_id, params)
201
- post("/api/v1/subscriptions/#{subscription_id}/pause-schedule", params)
201
+ post("/api/v1/subscriptions/#{subscription_id}/pause-schedule", body: params)
202
202
  end
203
203
 
204
204
  # Deletes/cancels a pending pause schedule for a subscription.
@@ -221,7 +221,7 @@ module Solidgate
221
221
  # @raise [InvalidRequestError] if subscription is invalid or already cancelled
222
222
  #
223
223
  def cancel_subscription(params)
224
- post("/api/v1/subscription/cancel", params)
224
+ post("/api/v1/subscription/cancel", body: params)
225
225
  end
226
226
 
227
227
  # Creates a new product in the Solidgate catalog.
@@ -234,7 +234,7 @@ module Solidgate
234
234
  # @raise [InvalidRequestError] if product parameters are invalid
235
235
  #
236
236
  def create_product(params)
237
- post("/api/v1/products", params)
237
+ post("/api/v1/products", body: params)
238
238
  end
239
239
 
240
240
  # Creates a new price for an existing product.
@@ -248,7 +248,7 @@ module Solidgate
248
248
  # @raise [InvalidRequestError] if product_id is invalid or price params are invalid
249
249
  #
250
250
  def create_price(product_id, params)
251
- post("/api/v1/products/#{product_id}/prices", params)
251
+ post("/api/v1/products/#{product_id}/prices", body: params)
252
252
  end
253
253
 
254
254
  # Retrieves all products from the Solidgate catalog.
@@ -322,7 +322,22 @@ module Solidgate
322
322
  # client.restore_subscription(subscription_id: 'sub_12345')
323
323
  #
324
324
  def restore_subscription(params)
325
- post("/api/v1/subscription/restore", params)
325
+ post("/api/v1/subscription/restore", body: params)
326
+ end
327
+
328
+ # Creates a refund for a transaction.
329
+ #
330
+ # @param params [Hash] refund parameters:
331
+ # - :order_id [String] the order identifier to refund
332
+ # - :amount [Integer] refund amount in minor units (for partial refunds)
333
+ # @return [Hash] refund response including refund status and details
334
+ # @raise [InvalidRequestError] if refund parameters are invalid
335
+ #
336
+ # @example Create a refund
337
+ # client.refund(order_id: 'ord_12345', amount: 1000)
338
+ #
339
+ def refund(params)
340
+ post("/api/v1/refund", body: params, base_url: "https://pay.solidgate.com")
326
341
  end
327
342
 
328
343
  private
@@ -347,8 +362,17 @@ module Solidgate
347
362
  # @return [Faraday::Connection] configured HTTP connection
348
363
  #
349
364
  def connection
350
- @connection ||= Faraday.new(
351
- url: config.api_url,
365
+ @connection ||= connection_for(config.api_url)
366
+ end
367
+
368
+ # Creates a Faraday HTTP connection for the specified base URL.
369
+ #
370
+ # @param base_url [String] the base URL for the connection
371
+ # @return [Faraday::Connection] configured HTTP connection
372
+ #
373
+ def connection_for(base_url)
374
+ Faraday.new(
375
+ url: base_url,
352
376
  headers: default_headers
353
377
  ) do |conn|
354
378
  conn.request :multipart
@@ -386,10 +410,11 @@ module Solidgate
386
410
  #
387
411
  # @param path [String] API endpoint path
388
412
  # @param body [Hash] request body parameters
413
+ # @param base_url [String, nil] optional base URL to override the default API URL
389
414
  # @return [Hash] parsed response body
390
415
  #
391
- def post(path, body = {})
392
- request(:post, path, body)
416
+ def post(path, body: {}, base_url: nil)
417
+ request(:post, path, body: body, base_url: base_url)
393
418
  end
394
419
 
395
420
  # Performs a PATCH request to the specified path.
@@ -398,8 +423,8 @@ module Solidgate
398
423
  # @param body [Hash] request body parameters
399
424
  # @return [Hash] parsed response body
400
425
  #
401
- def patch(path, body = {})
402
- request(:patch, path, body)
426
+ def patch(path, body: {})
427
+ request(:patch, path, body: body)
403
428
  end
404
429
 
405
430
  # Performs a DELETE request to the specified path.
@@ -416,16 +441,19 @@ module Solidgate
416
441
  # @param method [Symbol] HTTP method (:get, :post, :patch, :delete)
417
442
  # @param path [String] API endpoint path
418
443
  # @param body [Hash, nil] optional request body
444
+ # @param base_url [String, nil] optional base URL to override the default API URL
419
445
  # @return [Hash] parsed response body
420
446
  # @raise [TimeoutError] if request times out
421
447
  # @raise [ConnectionError] if connection fails
422
448
  # @raise [Error] for other unexpected errors
423
449
  #
424
- def request(method, path, body = nil)
450
+ def request(method, path, body: nil, base_url: nil)
425
451
  body_json = body ? JSON.generate(body) : ''
426
452
  signature = generate_signature(body_json)
427
453
 
428
- response = connection.send(method) do |req|
454
+ conn = base_url ? connection_for(base_url) : connection
455
+
456
+ response = conn.send(method) do |req|
429
457
  req.url path
430
458
  req.headers["Merchant"] = config.public_key
431
459
  req.headers["Signature"] = signature
@@ -64,14 +64,15 @@ module Solidgate
64
64
  # @param amount [Integer] amount to refund in cents (optional, defaults to full amount)
65
65
  # @param reason [String] refund reason (optional)
66
66
  # @return [Hash] refund response
67
- def refund(payment_id, amount: nil, reason: nil)
68
- raise ArgumentError, "payment_id is required" if payment_id.nil? || payment_id.empty?
67
+ def refund(order_id, amount: nil, reason: nil)
68
+ raise ArgumentError, "order_id is required" if order_id.nil? || order_id.empty?
69
69
 
70
70
  params = {}
71
- params[:amount] = amount if amount
72
- params[:reason] = reason if reason
71
+ params[:amount] = amount if amount
72
+ params[:reason] = reason if reason
73
+ params[:order_id] = order_id
73
74
 
74
- client.refund_payment(payment_id, params)
75
+ client.refund(params)
75
76
  end
76
77
 
77
78
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solidgate
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.10"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidgate-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hector Carrillo