Class: Solidgate::Client
- Inherits:
-
Object
- Object
- Solidgate::Client
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#capture_payment(payment_id, params = {}) ⇒ Hash
Capture a payment.
-
#create_payment(params) ⇒ Hash
Create a new payment.
- #create_price(product_id, params) ⇒ Object
- #create_product(params) ⇒ Object
-
#create_subscription(params) ⇒ Hash
Create a subscription.
- #generate_intent(params) ⇒ Object
- #generate_signature(json_string, public_key: config.public_key, private_key: config.private_key) ⇒ Object
-
#get_payment(payment_id) ⇒ Hash
Get payment status.
-
#initialize(options = Solidgate.configuration) ⇒ Client
constructor
A new instance of Client.
- #product_prices(product_id) ⇒ Object
- #products ⇒ Object
-
#refund_payment(payment_id, params = {}) ⇒ Hash
Refund a payment.
-
#settle_payment(params = {}) ⇒ Hash
Settle a payment.
-
#subscription_status(subscription_id) ⇒ Hash
Get subscription details.
-
#switch_subscription_product(params) ⇒ Hash
Update subscription product.
-
#void_payment(payment_id) ⇒ Hash
Void a payment.
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( = Solidgate.configuration) @config = build_config() @config.validate! end |
Instance Attribute Details
#config ⇒ Object (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
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
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
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
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 |
#products ⇒ Object
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
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
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
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
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
53 54 55 |
# File 'lib/solidgate/client.rb', line 53 def void_payment(payment_id) post("/v1/charge/#{payment_id}/void") end |