Class: AdvancedBilling::CouponsController

Inherits:
BaseController show all
Defined in:
lib/advanced_billing/controllers/coupons_controller.rb

Overview

CouponsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from AdvancedBilling::BaseController

Instance Method Details

#archive_coupon(product_family_id, coupon_id) ⇒ CouponResponse

Archives a coupon, making it unavailable for future use while remaining active on existing subscriptions. Archiving makes that Coupon unavailable for future use, but allows it to remain attached and functional on existing Subscriptions that are using it. The archived_at date and time will be assigned. Billing id of the product family to which the coupon belongs the coupon

Parameters:

  • product_family_id (Integer)

    Required parameter: The Advanced

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

Returns:



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 208

def archive_coupon(product_family_id,
                   coupon_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/product_families/{product_family_id}/coupons/{coupon_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_family_id, key: 'product_family_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash)))
    .execute
end

#create_coupon(product_family_id, body: nil) ⇒ CouponResponse

Creates a coupon under the specified product family. You can create either a flat amount coupon, by specifying amount_in_cents, or percentage coupon by specifying percentage. See [Apply Coupons to Subscriptions](https://maxio.zendesk.com/hc/en-us/articles/24261259337101- Coupons-and-Subscriptions) for information on applying a coupon to a subscription in the Advanced Billing UI. Billing id of the product family to which the coupon belongs here

Parameters:

  • product_family_id (Integer)

    Required parameter: The Advanced

  • body (CouponRequest) (defaults to: nil)

    Optional parameter: TODO: type description

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 21

def create_coupon(product_family_id,
                  body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/product_families/{product_family_id}/coupons.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_family_id, key: 'product_family_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#create_coupon_subcodes(coupon_id, body: nil) ⇒ CouponSubcodesResponse

Creates subcodes for an existing coupon. Coupon Subcodes allow you to create a set of unique codes that allow you to expand the use of one coupon. For example: Master Coupon Code:

  • SPRING2020 Coupon Subcodes:
  • SPRING90210
  • DP80302
  • SPRINGBALTIMORE When creating a coupon subcode, you must specify a coupon to attach it to using the coupon_id. Valid coupon subcodes are all capital letters, contain only letters and numbers, and do not have any spaces. Lowercase letters are capitalized before the subcode is created. Note: If you are using any of the allowed special characters ("%", "@", "+", "-", "_", and "."), you must encode them for use in the URL. % to %25 @ to %40
    • to %2B

Parameters:

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • body (CouponSubcodes) (defaults to: nil)

    Optional parameter: TODO: type description

Returns:



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 406

def create_coupon_subcodes(coupon_id,
                           body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/coupons/{coupon_id}/codes.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponSubcodesResponse.method(:from_hash)))
    .execute
end

#create_or_update_coupon_currency_prices(coupon_id, body: nil) ⇒ CouponCurrencyResponse

Creates and/or updates currency prices for an existing coupon. Multiple prices can be created or updated in a single request but each of the currencies must be defined on the site level already and the coupon must be an amount-based coupon, not percentage. Currency pricing for coupons must mirror the setup of the primary coupon pricing - if the primary coupon is percentage based, you will not be able to define pricing in non-primary currencies. the coupon description here

Parameters:

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • body (CouponCurrencyRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 346

def create_or_update_coupon_currency_prices(coupon_id,
                                            body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/coupons/{coupon_id}/currency_prices.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponCurrencyResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorStringMapResponseException))
    .execute
end

#delete_coupon_subcode(coupon_id, subcode) ⇒ void

This method returns an undefined value.

Deletes a specific subcode from a coupon.

Example

Given a coupon with an ID of 567, and a coupon subcode of 20OFF, the URL to DELETE this coupon subcode would be:

http://subdomain.chargify.com/coupons/567/codes/20OFF.<format>

Note: If you are using any of the allowed special characters (“%”, “@”, “+”, “-”, “_”, and “.”), you must encode them for use in the URL.

Special character Encoding
% %25
@ %40
+ %2B
%2D
_ %5F
. %2E

Percent Encoding Example

Or if the coupon subcode is 20%OFF, the URL to delete this coupon subcode would be: @https://.chargify.com/coupons/567/codes/20%25OFF.. the coupon to which the subcode belongs

Parameters:

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • subcode (String)

    Required parameter: The subcode of the coupon



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 518

def delete_coupon_subcode(coupon_id,
                          subcode)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/coupons/{coupon_id}/codes/{subcode}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(subcode, key: 'subcode')
                                .is_required(true)
                                .should_encode(true))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true)
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException))
    .execute
end

#find_coupon(product_family_id: nil, code: nil, currency_prices: nil) ⇒ CouponResponse

Searches for a coupon by code. If you have more than one product family and if the coupon you are trying to find does not belong to the default product family in your site, you need to specify (either in the URL or as a query string param) the product_family_id. Billing id of the product family to which the coupon belongs (Optional) If you have defined multiple currencies at the site level, you can pass ?currency_prices=true to include an array of currency price data in the response.

Parameters:

  • product_family_id (Integer) (defaults to: nil)

    Optional parameter: The Advanced

  • code (String) (defaults to: nil)

    Optional parameter: The code of the coupon

  • currency_prices (TrueClass | FalseClass) (defaults to: nil)

    Optional parameter:

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 101

def find_coupon(product_family_id: nil,
                code: nil,
                currency_prices: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons/find.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(product_family_id, key: 'product_family_id'))
               .query_param(new_parameter(code, key: 'code'))
               .query_param(new_parameter(currency_prices, key: 'currency_prices'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash)))
    .execute
end

#list_coupon_subcodes(options = {}) ⇒ CouponSubcodes

Lists the subcodes attached to a coupon. the coupon pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query page=1. many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query per_page=200.

Parameters:

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

Returns:



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 441

def list_coupon_subcodes(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons/{coupon_id}/codes.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(options['coupon_id'], key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponSubcodes.method(:from_hash)))
    .execute
end

#list_coupons(options = {}) ⇒ Array[CouponResponse]

Lists coupons for a site. pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query page=1. many records to fetch in each request. Default value is 30. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query per_page=200. List Coupons operations (Optional) If you have defined multiple currencies at the site level, you can pass ?currency_prices=true to include an array of currency price data in the response. Use in query currency_prices=true.

Parameters:

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • filter (ListCouponsFilter)

    Optional parameter: Filter to use for

  • currency_prices (TrueClass | FalseClass)

    Optional parameter:

Returns:



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 247

def list_coupons(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .query_param(new_parameter(options['currency_prices'], key: 'currency_prices'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#list_coupons_for_product_family(options = {}) ⇒ Array[CouponResponse]

Lists coupons for a specific product family in a site. Billing id of the product family to which the coupon belongs pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query page=1. many records to fetch in each request. Default value is 30. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query per_page=200. List Coupons operations (Optional) If you have defined multiple currencies at the site level, you can pass ?currency_prices=true to include an array of currency price data in the response. Use in query currency_prices=true.

Parameters:

  • product_family_id (Integer)

    Required parameter: The Advanced

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • filter (ListCouponsFilter)

    Optional parameter: Filter to use for

  • currency_prices (TrueClass | FalseClass)

    Optional parameter:

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 66

def list_coupons_for_product_family(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/product_families/{product_family_id}/coupons.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(options['product_family_id'], key: 'product_family_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .query_param(new_parameter(options['currency_prices'], key: 'currency_prices'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#read_coupon(product_family_id, coupon_id, currency_prices: nil) ⇒ CouponResponse

Returns a coupon by its system-assigned ID. You must identify the Coupon in this call by the ID parameter assigned to it. If instead you would like to find a Coupon using a Coupon code, use the Find Coupon endpoint. If the coupon is set to use_site_exchange_rate: true, it returns pricing based on the current exchange rate. If the flag is set to false, it returns all of the defined prices for each currency. Billing id of the product family to which the coupon belongs the coupon (Optional) If you have defined multiple currencies at the site level, you can pass ?currency_prices=true to include an array of currency price data in the response.

Parameters:

  • product_family_id (Integer)

    Required parameter: The Advanced

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • currency_prices (TrueClass | FalseClass) (defaults to: nil)

    Optional parameter:

Returns:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 135

def read_coupon(product_family_id,
                coupon_id,
                currency_prices: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/product_families/{product_family_id}/coupons/{coupon_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_family_id, key: 'product_family_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(currency_prices, key: 'currency_prices'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash)))
    .execute
end

#read_coupon_usage(product_family_id, coupon_id) ⇒ Array[CouponUsage]

Lists coupon usage details, one entry per product. Billing id of the product family to which the coupon belongs. the coupon.

Parameters:

  • product_family_id (Integer)

    Required parameter: The Advanced

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

Returns:



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 272

def read_coupon_usage(product_family_id,
                      coupon_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/product_families/{product_family_id}/coupons/{coupon_id}/usage.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_family_id, key: 'product_family_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponUsage.method(:from_hash))
                .is_response_array(true))
    .execute
end

#update_coupon(product_family_id, coupon_id, body: nil) ⇒ CouponResponse

Updates a coupon. You can restrict a coupon to only apply to specific products / components by optionally passing in hashes of restricted_products and/or restricted_components in the format: { "<product/component_id>": boolean_value } Billing id of the product family to which the coupon belongs the coupon here

Parameters:

  • product_family_id (Integer)

    Required parameter: The Advanced

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • body (CouponRequest) (defaults to: nil)

    Optional parameter: TODO: type description

Returns:



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 169

def update_coupon(product_family_id,
                  coupon_id,
                  body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/product_families/{product_family_id}/coupons/{coupon_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(product_family_id, key: 'product_family_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#update_coupon_subcodes(coupon_id, body: nil) ⇒ CouponSubcodesResponse

Updates the subcodes for a coupon, replacing all existing subcodes with the new list. Send an array of new coupon subcodes. Note: All current subcodes for that Coupon will be deleted first, and replaced with the list of subcodes sent to this endpoint. The response will contain:

  • The created subcodes,
  • Subcodes that were not created because they already exist,
  • Any subcodes not created because they are invalid. the coupon here

Parameters:

  • coupon_id (Integer)

    Required parameter: The Advanced Billing id of

  • body (CouponSubcodes) (defaults to: nil)

    Optional parameter: TODO: type description

Returns:



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 473

def update_coupon_subcodes(coupon_id,
                           body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/coupons/{coupon_id}/codes.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponSubcodesResponse.method(:from_hash)))
    .execute
end

#validate_coupon(code, product_family_id: nil) ⇒ CouponResponse

Verifies whether a specific coupon code is valid. This method is useful for validating coupon codes that are entered by a customer. If you have more than one product family and if the coupon you are validating does not belong to the first product family in your site, you need to specify the product family, either in the URL or as a query string param. This can be done by supplying the id or the handle in the handle:my-family format. Supplying the product_family_handle in the URL:

https://<subdomain>.chargify.com/product_families/handle:<product_family_h
andle>/coupons/validate.<format>?code=<coupon_code>

Supplying the product_family_id as a query parameter:

https://<subdomain>.chargify.com/coupons/validate.<format>?code=<coupon_co
de>&product_family_id=<id>

Billing id of the product family to which the coupon belongs

Parameters:

  • code (String)

    Required parameter: The code of the coupon

  • product_family_id (Integer) (defaults to: nil)

    Optional parameter: The Advanced

Returns:



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/advanced_billing/controllers/coupons_controller.rb', line 314

def validate_coupon(code,
                    product_family_id: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons/validate.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(code, key: 'code')
                             .is_required(true))
               .query_param(new_parameter(product_family_id, key: 'product_family_id'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CouponResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found: \'{$response.body}\'',
                                      SingleStringErrorResponseException))
    .execute
end