Class: Stigg::Resources::V1::Coupons
- Inherits:
-
Object
- Object
- Stigg::Resources::V1::Coupons
- Defined in:
- lib/stigg/resources/v1/coupons.rb
Overview
Operations related to coupons
Instance Method Summary collapse
-
#archive_coupon(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponArchiveCouponParams for more details.
-
#create(id:, amounts_off:, description:, duration_in_months:, metadata:, name:, percent_off:, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponCreateParams for more details.
-
#initialize(client:) ⇒ Coupons
constructor
private
A new instance of Coupons.
-
#list(id: nil, after: nil, before: nil, created_at: nil, limit: nil, status: nil, type: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::CouponListResponse>
Some parameter documentations has been truncated, see Models::V1::CouponListParams for more details.
-
#retrieve(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponRetrieveParams for more details.
-
#update_coupon(id, description: nil, metadata: nil, name: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponUpdateCouponParams for more details.
Constructor Details
#initialize(client:) ⇒ Coupons
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Coupons.
204 205 206 |
# File 'lib/stigg/resources/v1/coupons.rb', line 204 def initialize(client:) @client = client end |
Instance Method Details
#archive_coupon(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponArchiveCouponParams for more details.
Archives a coupon, preventing it from being applied to new subscriptions.
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/stigg/resources/v1/coupons.rb', line 150 def archive_coupon(id, params = {}) parsed, = Stigg::V1::CouponArchiveCouponParams.dump_request(params) @client.request( method: :post, path: ["api/v1/coupons/%1$s/archive", id], headers: parsed.transform_keys( x_account_id: "x-account-id", x_environment_id: "x-environment-id" ), model: Stigg::V1::Coupon, options: ) end |
#create(id:, amounts_off:, description:, duration_in_months:, metadata:, name:, percent_off:, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponCreateParams for more details.
Creates a new discount coupon with percentage or fixed amount off, applicable to customer subscriptions.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/stigg/resources/v1/coupons.rb', line 39 def create(params) parsed, = Stigg::V1::CouponCreateParams.dump_request(params) header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"} @client.request( method: :post, path: "api/v1/coupons", headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stigg::V1::Coupon, options: ) end |
#list(id: nil, after: nil, before: nil, created_at: nil, limit: nil, status: nil, type: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::CouponListResponse>
Some parameter documentations has been truncated, see Models::V1::CouponListParams for more details.
Retrieves a paginated list of coupons in the environment.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/stigg/resources/v1/coupons.rb', line 114 def list(params = {}) query_params = [:id, :after, :before, :created_at, :limit, :status, :type] parsed, = Stigg::V1::CouponListParams.dump_request(params) query = Stigg::Internal::Util.encode_query_params(parsed.slice(*query_params)) @client.request( method: :get, path: "api/v1/coupons", query: query.transform_keys(created_at: "createdAt"), headers: parsed.except(*query_params).transform_keys( x_account_id: "x-account-id", x_environment_id: "x-environment-id" ), page: Stigg::Internal::MyCursorIDPage, model: Stigg::Models::V1::CouponListResponse, options: ) end |
#retrieve(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponRetrieveParams for more details.
Retrieves a coupon by its unique identifier.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/stigg/resources/v1/coupons.rb', line 70 def retrieve(id, params = {}) parsed, = Stigg::V1::CouponRetrieveParams.dump_request(params) @client.request( method: :get, path: ["api/v1/coupons/%1$s", id], headers: parsed.transform_keys( x_account_id: "x-account-id", x_environment_id: "x-environment-id" ), model: Stigg::V1::Coupon, options: ) end |
#update_coupon(id, description: nil, metadata: nil, name: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Some parameter documentations has been truncated, see Models::V1::CouponUpdateCouponParams for more details.
Updates an existing coupon’s properties such as name, description, and metadata.
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/stigg/resources/v1/coupons.rb', line 188 def update_coupon(id, params = {}) parsed, = Stigg::V1::CouponUpdateCouponParams.dump_request(params) header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"} @client.request( method: :patch, path: ["api/v1/coupons/%1$s", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stigg::V1::Coupon, options: ) end |