Create a new voucher

Content

Resource URL

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

Examples

Creating a pricetype voucher

Whenever you want to lock specific pricetypes with a vouchercode, a pricetype voucher is needed. This type of voucher can be created in the following way.

Ticketlayoutid is not specified in this example but is necessary whenever vouchercodes are generated that need to be delivered to an enduser via a ticketlayout template.

Request

 1use Ticketmatic\Endpoints\Settings\Vouchers;
 2
 3$result = Vouchers::create($client, array(
 4    "typeid" => 24001,
 5    "name" => "Pricetype voucher",
 6    "codeformatid" => 27001,
 7    "description" => "This voucher can be used to buy tickets for a specific locked pricetype in an event",
 8    "validity" => array(
 9        "expiry_monthsaftercreation" => 12,
10        "maxusages" => 10,
11        "maxusagesperevent" => 1,
12    ),
13));

Response

 1object(\Ticketmatic\Model\Voucher) (8) {
 2  ["id"]=>
 3  int(0)
 4  ["typeid"]=>
 5  int(0)
 6  ["name"]=>
 7  string(17) "Pricetype voucher"
 8  ["codeformatid"]=>
 9  int(0)
10  ["description"]=>
11  string(83) "This voucher can be used to buy tickets for a specific locked pricetype in an event"
12  ["nbrofcodes"]=>
13  int(0)
14  ["validity"]=>
15  object(\Ticketmatic\Model\VoucherValidity) (3) {
16    ["expiry_monthsaftercreation"]=>
17    int(0)
18    ["maxusages"]=>
19    int(0)
20    ["maxusagesperevent"]=>
21    int(0)
22  }
23  ["isarchived"]=>
24  bool(false)
25}

Request

 1import (
 2    "github.com/ticketmatic/tm-go/ticketmatic"
 3    "github.com/ticketmatic/tm-go/ticketmatic/settings/vouchers"
 4)
 5
 6result, err := vouchers.Create(client, &ticketmatic.Voucher{
 7    Typeid: 24001,
 8    Name: "Pricetype voucher",
 9    Codeformatid: 27001,
10    Description: "This voucher can be used to buy tickets for a specific locked pricetype in an event",
11    Validity: &ticketmatic.VoucherValidity{
12        ExpiryMonthsaftercreation: 12,
13        Maxusages: 10,
14        Maxusagesperevent: 1,
15    },
16})

Response

 1result := &ticketmatic.Voucher{
 2    Id: 10000,
 3    Typeid: 24001,
 4    Name: "Pricetype voucher",
 5    Codeformatid: 27001,
 6    Description: "This voucher can be used to buy tickets for a specific locked pricetype in an event",
 7    Nbrofcodes: 0,
 8    Validity: &ticketmatic.VoucherValidity{
 9        ExpiryMonthsaftercreation: 12,
10        Maxusages: 10,
11        Maxusagesperevent: 1,
12    },
13    Isarchived: false,
14}

Request

 1POST /api/1/{accountname}/settings/vouchers HTTP/1.1
 2Content-Type: application/json
 3
 4{
 5    "typeid": 24001,
 6    "name": "Pricetype voucher",
 7    "codeformatid": 27001,
 8    "description": "This voucher can be used to buy tickets for a specific locked pricetype in an event",
 9    "validity": {
10        "expiry_monthsaftercreation": 12,
11        "maxusages": 10,
12        "maxusagesperevent": 1
13    }
14}

Response

 1HTTP/1.1 200 OK
 2Content-Type: application/json
 3
 4{
 5    "id": 10000,
 6    "typeid": 24001,
 7    "name": "Pricetype voucher",
 8    "codeformatid": 27001,
 9    "description": "This voucher can be used to buy tickets for a specific locked pricetype in an event",
10    "nbrofcodes": 0,
11    "validity": {
12        "expiry_monthsaftercreation": 12,
13        "maxusages": 10,
14        "maxusagesperevent": 1
15    },
16    "isarchived": false
17}

Creating a payment voucher

If you want to create voucher that generates codes which which can be used for paying, a payment voucher is needed.

Ticketlayoutid is not specified in this example but is necessary whenever vouchercodes are generated that need to be delivered to an enduser via a ticketlayout template.

The paymentmethodid (13) that is used in this example is of a voucher type (paymentmethodtypeid of 1007).

Request

 1use Ticketmatic\Endpoints\Settings\Vouchers;
 2
 3$result = Vouchers::create($client, array(
 4    "typeid" => 24003,
 5    "name" => "Payment voucher",
 6    "codeformatid" => 27001,
 7    "description" => "A code that is generated by this voucher can be used for making payments.",
 8    "paymentmethodid" => 13,
 9    "validity" => array(
10        "expiry_monthsaftercreation" => 12,
11    ),
12));

Response

 1object(\Ticketmatic\Model\Voucher) (9) {
 2  ["id"]=>
 3  int(0)
 4  ["typeid"]=>
 5  int(0)
 6  ["name"]=>
 7  string(15) "Payment voucher"
 8  ["codeformatid"]=>
 9  int(0)
10  ["description"]=>
11  string(73) "A code that is generated by this voucher can be used for making payments."
12  ["nbrofcodes"]=>
13  int(0)
14  ["paymentmethodid"]=>
15  int(0)
16  ["validity"]=>
17  object(\Ticketmatic\Model\VoucherValidity) (1) {
18    ["expiry_monthsaftercreation"]=>
19    int(0)
20  }
21  ["isarchived"]=>
22  bool(false)
23}

Request

 1import (
 2    "github.com/ticketmatic/tm-go/ticketmatic"
 3    "github.com/ticketmatic/tm-go/ticketmatic/settings/vouchers"
 4)
 5
 6result, err := vouchers.Create(client, &ticketmatic.Voucher{
 7    Typeid: 24003,
 8    Name: "Payment voucher",
 9    Codeformatid: 27001,
10    Description: "A code that is generated by this voucher can be used for making payments.",
11    Paymentmethodid: 13,
12    Validity: &ticketmatic.VoucherValidity{
13        ExpiryMonthsaftercreation: 12,
14    },
15})

Response

 1result := &ticketmatic.Voucher{
 2    Id: 10001,
 3    Typeid: 24003,
 4    Name: "Payment voucher",
 5    Codeformatid: 27001,
 6    Description: "A code that is generated by this voucher can be used for making payments.",
 7    Nbrofcodes: 0,
 8    Paymentmethodid: 13,
 9    Validity: &ticketmatic.VoucherValidity{
10        ExpiryMonthsaftercreation: 12,
11    },
12    Isarchived: false,
13}

Request

 1POST /api/1/{accountname}/settings/vouchers HTTP/1.1
 2Content-Type: application/json
 3
 4{
 5    "typeid": 24003,
 6    "name": "Payment voucher",
 7    "codeformatid": 27001,
 8    "description": "A code that is generated by this voucher can be used for making payments.",
 9    "paymentmethodid": 13,
10    "validity": {
11        "expiry_monthsaftercreation": 12
12    }
13}

Response

 1HTTP/1.1 200 OK
 2Content-Type: application/json
 3
 4{
 5    "id": 10001,
 6    "typeid": 24003,
 7    "name": "Payment voucher",
 8    "codeformatid": 27001,
 9    "description": "A code that is generated by this voucher can be used for making payments.",
10    "nbrofcodes": 0,
11    "paymentmethodid": 13,
12    "validity": {
13        "expiry_monthsaftercreation": 12
14    },
15    "isarchived": false
16}

Request body fields

FieldDescription
typeid
int 
(required)

Type ID

Example value:24001
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