Modify an existing voucher

Content

Resource URL

https://apps.ticketmatic.com/api/1/{accountname}/settings/vouchers/{id}

Example

Request

 1use Ticketmatic\Endpoints\Settings\Vouchers;
 2
 3$result = Vouchers::update($client, $id, array(
 4    "name" => "Gift voucher",
 5    "codeformatid" => 27001,
 6    "codeprefix" => "998",
 7    "description" => "Gift voucher description",
 8    "ordervalidationscript" => "return order.tickets.count<5;",
 9    "paymentmethodid" => 345,
10    "validity" => array(
11        "expiry_fixeddate" => "2025-01-01",
12        "maxusages" => 10,
13        "maxusagesperevent" => 2,
14    ),
15));

Response

 1object(\Ticketmatic\Model\Voucher) (13) {
 2  ["id"]=>
 3  int(0)
 4  ["typeid"]=>
 5  int(0)
 6  ["name"]=>
 7  string(12) "Gift voucher"
 8  ["codeformatid"]=>
 9  int(0)
10  ["codeprefix"]=>
11  string(3) "998"
12  ["description"]=>
13  string(24) "Gift voucher description"
14  ["nbrofcodes"]=>
15  int(0)
16  ["ordervalidationscript"]=>
17  string(29) "return order.tickets.count<5;"
18  ["paymentmethodid"]=>
19  int(0)
20  ["validity"]=>
21  object(\Ticketmatic\Model\VoucherValidity) (3) {
22    ["expiry_fixeddate"]=>
23    object(\DateTime) (3) {
24      ["date"]=>
25      string(26) "2025-01-01.000000"
26      ["timezone_type"]=>
27      int(3)
28      ["timezone"]=>
29      string(3) "UTC"
30    }
31    ["maxusages"]=>
32    int(0)
33    ["maxusagesperevent"]=>
34    int(0)
35  }
36  ["isarchived"]=>
37  bool(false)
38  ["createdts"]=>
39  object(\DateTime) (3) {
40    ["date"]=>
41    string(26) "2014-09-26 15:24:36.000000"
42    ["timezone_type"]=>
43    int(3)
44    ["timezone"]=>
45    string(3) "UTC"
46  }
47  ["lastupdatets"]=>
48  object(\DateTime) (3) {
49    ["date"]=>
50    string(26) "2014-09-26 15:24:36.000000"
51    ["timezone_type"]=>
52    int(3)
53    ["timezone"]=>
54    string(3) "UTC"
55  }
56}

Request

 1import (
 2    "github.com/ticketmatic/tm-go/ticketmatic"
 3    "github.com/ticketmatic/tm-go/ticketmatic/settings/vouchers"
 4)
 5
 6result, err := vouchers.Update(client, id, &ticketmatic.Voucher{
 7    Name: "Gift voucher",
 8    Codeformatid: 27001,
 9    Codeprefix: "998",
10    Description: "Gift voucher description",
11    Ordervalidationscript: "return order.tickets.count<5;",
12    Paymentmethodid: 345,
13    Validity: &ticketmatic.VoucherValidity{
14        ExpiryFixeddate: ticketmatic.NewTime(ticketmatic.MustParseTime("2025-01-01")),
15        Maxusages: 10,
16        Maxusagesperevent: 2,
17    },
18})

Response

 1result := &ticketmatic.Voucher{
 2    Id: 123,
 3    Typeid: 24001,
 4    Name: "Gift voucher",
 5    Codeformatid: 27001,
 6    Codeprefix: "998",
 7    Description: "Gift voucher description",
 8    Nbrofcodes: 10000,
 9    Ordervalidationscript: "return order.tickets.count<5;",
10    Paymentmethodid: 345,
11    Validity: &ticketmatic.VoucherValidity{
12        ExpiryFixeddate: ticketmatic.NewTime(ticketmatic.MustParseTime("2025-01-01")),
13        Maxusages: 10,
14        Maxusagesperevent: 2,
15    },
16    Isarchived: false,
17    Createdts: ticketmatic.NewTime(ticketmatic.MustParseTime("2014-09-26 15:24:36")),
18    Lastupdatets: ticketmatic.NewTime(ticketmatic.MustParseTime("2014-09-26 15:24:36")),
19}

Request

 1PUT /api/1/{accountname}/settings/vouchers/{id} HTTP/1.1
 2Content-Type: application/json
 3
 4{
 5    "name": "Gift voucher",
 6    "codeformatid": 27001,
 7    "codeprefix": "998",
 8    "description": "Gift voucher description",
 9    "ordervalidationscript": "return order.tickets.count<5;",
10    "paymentmethodid": 345,
11    "validity": {
12        "expiry_fixeddate": "2025-01-01",
13        "maxusages": 10,
14        "maxusagesperevent": 2
15    }
16}

Response

 1HTTP/1.1 200 OK
 2Content-Type: application/json
 3
 4{
 5    "id": 123,
 6    "typeid": 24001,
 7    "name": "Gift voucher",
 8    "codeformatid": 27001,
 9    "codeprefix": "998",
10    "description": "Gift voucher description",
11    "nbrofcodes": 10000,
12    "ordervalidationscript": "return order.tickets.count<5;",
13    "paymentmethodid": 345,
14    "validity": {
15        "expiry_fixeddate": "2025-01-01",
16        "maxusages": 10,
17        "maxusagesperevent": 2
18    },
19    "isarchived": false,
20    "createdts": "2014-09-26 15:24:36",
21    "lastupdatets": "2014-09-26 15:24:36"
22}

Request body fields

FieldDescription
name
mlstring 
(required)

Name of the voucher

Example value:"Gift voucher"
codeformatid
int 
(required)

Format used when generating codes for the voucher. Possible values:

  • 27001: 12 digits
  • 27002: 16 digits
  • 27003: 8 alphanumerical characters
  • 27004: 12 alphanumerical characters
  • 27005: 16 alphanumerical characters
  • 27099: Specified from list, not autogenerated
Example value:27001
codeprefix
string 
(required)

If set, the codes that are generated are padded with this prefix. This can be used to ensure that vouchercodes are unique. The prefix can be max 10 characters long.

Example value:"998"
description
mlstring 
(required)

Description of the voucher

Example value:"Gift voucher description"
ordervalidationscript
string

A validation script that is used for vouchers of type order. For each order with a voucher of this type attached, the script will be run to validate the contents

Example value:"return order.tickets.count<5;"
paymentmethodid
int

Paymentmethod to use when creating payments for vouchers of type payment. This field is required when a payment voucher is created. The paymentmethod that is referred to should be of a voucher type.

Example value:345
validity
VoucherValidity 
(required)

Definition of the validity of this voucher. Depends on the typeid.

Example value:{ "expiry_fixeddate": "2025-01-01", "maxusages": 10, "maxusagesperevent": 2 }

Type reference: Voucher

Result fields

FieldDescription
id
int

Unique ID

Example value:123
typeid
int

Type ID

Example value:24001
name

Name of the voucher

Example value:"Gift voucher"
codeformatid
int

Format used when generating codes for the voucher. Possible values:

  • 27001: 12 digits
  • 27002: 16 digits
  • 27003: 8 alphanumerical characters
  • 27004: 12 alphanumerical characters
  • 27005: 16 alphanumerical characters
  • 27099: Specified from list, not autogenerated
Example value:27001
codeprefix
string

If set, the codes that are generated are padded with this prefix. This can be used to ensure that vouchercodes are unique. The prefix can be max 10 characters long.

Example value:"998"
description

Description of the voucher

Example value:"Gift voucher description"
nbrofcodes
int

The number of codes that were created for this voucher.

Example value:10000
ordervalidationscript
string

A validation script that is used for vouchers of type order. For each order with a voucher of this type attached, the script will be run to validate the contents

Example value:"return order.tickets.count<5;"
paymentmethodid
int

Paymentmethod to use when creating payments for vouchers of type payment. This field is required when a payment voucher is created. The paymentmethod that is referred to should be of a voucher type.

Example value:345
validity

Definition of the validity of this voucher. Depends on the typeid.

Example value:{ "expiry_fixeddate": "2025-01-01", "maxusages": 10, "maxusagesperevent": 2 }
isarchived
bool

Whether or not this item is archived

createdts
timestamp

Created timestamp

Example value:"2014-09-26 15:24:36"
lastupdatets
timestamp

Last updated timestamp

Example value:"2014-09-26 15:24:36"

Type reference: Voucher