Class: Pago::V2026_04::Services::Subscriptions
- Defined in:
- lib/pago/v2026_04/services/subscriptions.rb,
sig/pago/v2026_04/generated.rbs
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#create(body: {}) ⇒ Models::Subscription
Create a subscription programmatically.
-
#export(organization_id: nil) ⇒ String
Export subscriptions as a CSV file.
-
#get(id) ⇒ Models::Subscription
Get a subscription by ID.
-
#list(organization_id: nil, product_id: nil, customer_id: nil, external_customer_id: nil, discount_id: nil, active: nil, status: nil, cancel_at_period_end: nil, customer_cancellation_reason: nil, canceled_at_after: nil, canceled_at_before: nil, page: 1, limit: 10, sorting: ["-started_at"], metadata: nil) ⇒ Models::ListResourceSubscription
List subscriptions.
-
#list_each(organization_id: nil, product_id: nil, customer_id: nil, external_customer_id: nil, discount_id: nil, active: nil, status: nil, cancel_at_period_end: nil, customer_cancellation_reason: nil, canceled_at_after: nil, canceled_at_before: nil, limit: 10, sorting: ["-started_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of
list, fetching pages on demand. -
#revoke(id) ⇒ Models::Subscription
Revoke a subscription, i.e cancel immediately.
-
#update(id, body: {}) ⇒ Models::Subscription
Update a subscription.
Methods inherited from Service
Constructor Details
This class inherits a constructor from Pago::Service
Instance Method Details
#create(body: {}) ⇒ Models::Subscription
Create a subscription programmatically.
This endpoint only allows to create subscription on free products. For paid products, use the checkout flow.
No initial order will be created and no confirmation email will be sent.
Scopes: subscriptions:write
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 65 def create(body: {}) data = client.request( http_method: "POST", path: "/v1/subscriptions/", path_params: {}, query: {}, body: body, response_type: :json, errors: { 422 => Errors::HTTPValidationError } ) Models::Subscription.from_json(data) end |
#export(organization_id: nil) ⇒ String
Export subscriptions as a CSV file.
Scopes: subscriptions:read subscriptions:write
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 86 def export(organization_id: nil) client.request( http_method: "GET", path: "/v1/subscriptions/export", path_params: {}, query: { "organization_id" => organization_id }, response_type: :text, errors: { 422 => Errors::HTTPValidationError } ) end |
#get(id) ⇒ Models::Subscription
Get a subscription by ID.
Scopes: subscriptions:read subscriptions:write
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 106 def get(id) data = client.request( http_method: "GET", path: "/v1/subscriptions/{id}", path_params: { "id" => id }, query: {}, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Models::Subscription.from_json(data) end |
#list(organization_id: nil, product_id: nil, customer_id: nil, external_customer_id: nil, discount_id: nil, active: nil, status: nil, cancel_at_period_end: nil, customer_cancellation_reason: nil, canceled_at_after: nil, canceled_at_before: nil, page: 1, limit: 10, sorting: ["-started_at"], metadata: nil) ⇒ Models::ListResourceSubscription
List subscriptions.
Scopes: subscriptions:read subscriptions:write
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 29 def list(organization_id: nil, product_id: nil, customer_id: nil, external_customer_id: nil, discount_id: nil, active: nil, status: nil, cancel_at_period_end: nil, customer_cancellation_reason: nil, canceled_at_after: nil, canceled_at_before: nil, page: 1, limit: 10, sorting: ["-started_at"], metadata: nil) data = client.request( http_method: "GET", path: "/v1/subscriptions/", path_params: {}, query: { "organization_id" => organization_id, "product_id" => product_id, "customer_id" => customer_id, "external_customer_id" => external_customer_id, "discount_id" => discount_id, "active" => active, "status" => status, "cancel_at_period_end" => cancel_at_period_end, "customer_cancellation_reason" => customer_cancellation_reason, "canceled_at_after" => canceled_at_after, "canceled_at_before" => canceled_at_before, "page" => page, "limit" => limit, "sorting" => sorting, "metadata" => }, response_type: :json, errors: { 422 => Errors::HTTPValidationError } ) Models::ListResourceSubscription.from_json(data) end |
#list_each(organization_id: nil, product_id: nil, customer_id: nil, external_customer_id: nil, discount_id: nil, active: nil, status: nil, cancel_at_period_end: nil, customer_cancellation_reason: nil, canceled_at_after: nil, canceled_at_before: nil, limit: 10, sorting: ["-started_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of list, fetching pages on demand.
45 46 47 48 49 50 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 45 def list_each(organization_id: nil, product_id: nil, customer_id: nil, external_customer_id: nil, discount_id: nil, active: nil, status: nil, cancel_at_period_end: nil, customer_cancellation_reason: nil, canceled_at_after: nil, canceled_at_before: nil, limit: 10, sorting: ["-started_at"], metadata: nil, &block) paginator = ::Pago::Paginator.new do |page_number| list(organization_id: organization_id, product_id: product_id, customer_id: customer_id, external_customer_id: external_customer_id, discount_id: discount_id, active: active, status: status, cancel_at_period_end: cancel_at_period_end, customer_cancellation_reason: customer_cancellation_reason, canceled_at_after: canceled_at_after, canceled_at_before: canceled_at_before, page: page_number, limit: limit, sorting: sorting, metadata: ) end block ? paginator.each(&block) : paginator end |
#revoke(id) ⇒ Models::Subscription
Revoke a subscription, i.e cancel immediately.
Scopes: subscriptions:write
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 129 def revoke(id) data = client.request( http_method: "DELETE", path: "/v1/subscriptions/{id}", path_params: { "id" => id }, query: {}, response_type: :json, errors: { 403 => Errors::AlreadyCanceledSubscription, 404 => Errors::ResourceNotFound, 409 => Errors::SubscriptionLocked, 422 => Errors::HTTPValidationError } ) Models::Subscription.from_json(data) end |
#update(id, body: {}) ⇒ Models::Subscription
Update a subscription.
Scopes: subscriptions:write
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/pago/v2026_04/services/subscriptions.rb', line 154 def update(id, body: {}) data = client.request( http_method: "PATCH", path: "/v1/subscriptions/{id}", path_params: { "id" => id }, query: {}, body: body, response_type: :json, errors: { 402 => Errors::PaymentFailed, 403 => Errors::AlreadyCanceledSubscription, 404 => Errors::ResourceNotFound, 409 => Errors::SubscriptionLocked, 422 => Errors::HTTPValidationError } ) Models::Subscription.from_json(data) end |