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, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Archives a coupon, preventing it from being applied to new subscriptions.
-
#create(id:, amounts_off:, description:, duration_in_months:, metadata:, name:, percent_off:, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Creates a new discount coupon with percentage or fixed amount off, applicable to customer subscriptions.
-
#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, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::CouponListResponse>
Retrieves a paginated list of coupons in the environment.
-
#retrieve(id, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Retrieves a coupon by its unique identifier.
-
#update_coupon(id, description: nil, metadata: nil, name: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Updates an existing coupon’s properties such as name, description, and metadata.
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.
150 151 152 |
# File 'lib/stigg/resources/v1/coupons.rb', line 150 def initialize(client:) @client = client end |
Instance Method Details
#archive_coupon(id, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Archives a coupon, preventing it from being applied to new subscriptions.
110 111 112 113 114 115 116 117 |
# File 'lib/stigg/resources/v1/coupons.rb', line 110 def archive_coupon(id, params = {}) @client.request( method: :post, path: ["api/v1/coupons/%1$s/archive", id], model: Stigg::V1::Coupon, options: params[:request_options] ) end |
#create(id:, amounts_off:, description:, duration_in_months:, metadata:, name:, percent_off:, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Creates a new discount coupon with percentage or fixed amount off, applicable to customer subscriptions.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/stigg/resources/v1/coupons.rb', line 32 def create(params) parsed, = Stigg::V1::CouponCreateParams.dump_request(params) @client.request( method: :post, path: "api/v1/coupons", body: parsed, model: Stigg::V1::Coupon, options: ) end |
#list(id: nil, after: nil, before: nil, created_at: nil, limit: nil, status: nil, type: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::CouponListResponse>
Retrieves a paginated list of coupons in the environment.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/stigg/resources/v1/coupons.rb', line 86 def list(params = {}) parsed, = Stigg::V1::CouponListParams.dump_request(params) query = Stigg::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: "api/v1/coupons", query: query.transform_keys(created_at: "createdAt"), page: Stigg::Internal::MyCursorIDPage, model: Stigg::Models::V1::CouponListResponse, options: ) end |
#retrieve(id, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Retrieves a coupon by its unique identifier.
54 55 56 57 58 59 60 61 |
# File 'lib/stigg/resources/v1/coupons.rb', line 54 def retrieve(id, params = {}) @client.request( method: :get, path: ["api/v1/coupons/%1$s", id], model: Stigg::V1::Coupon, options: params[:request_options] ) end |
#update_coupon(id, description: nil, metadata: nil, name: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon
Updates an existing coupon’s properties such as name, description, and metadata.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/stigg/resources/v1/coupons.rb', line 136 def update_coupon(id, params = {}) parsed, = Stigg::V1::CouponUpdateCouponParams.dump_request(params) @client.request( method: :patch, path: ["api/v1/coupons/%1$s", id], body: parsed, model: Stigg::V1::Coupon, options: ) end |