voucherifyio / voucherify-dotNET-sdk

.Net SDK for Voucherify - coupons, vouchers, promo codes http://www.voucherify.io
http://www.voucherify.io
MIT License
12 stars 16 forks source link

Voucher type is not optional in Vouchers.Create #112

Open carlosmota-bloop opened 1 month ago

carlosmota-bloop commented 1 month ago

I'm trying to create a new referral code voucher in a referral campaign.

I experimented with the API docs and managed to do it via this endpoint (https://docs.voucherify.io/reference/generate-random-code)

Request: POST https://api.voucherify.io/v1/vouchers

Body:

{
  "expiration_date": "2024-09-06T00:00:00.000Z",
  "campaign": "Bloop Referral Program"
}

This creates a referral code with a code that follows the code config of the campaign, as expected.


I'm trying to achieve the same result using the .net SDK with this code:

var voucherCreate = new VoucherCreate()
{
    ExpirationDate = DateTime.UtcNow.AddDays(30),
    Campaign = "Bloop Referral Program",
    Metadata = metadata,
};

var createdVoucher = await _api.Vouchers.Create(voucherCreate);

But the response is: VoucherifyError[code=400, key='invalid_voucher, message='Invalid Voucher', details='Voucher type does not match provided campaign type'].

By checking the audit logs, it seems that the generated request includes the voucher type is set as DISCOUNT_VOUCHER. This is the request body

{
    type: "DISCOUNT_VOUCHER",
    campaign: "Bloop Referral Program",
    expiration_date: "2024-09-06T09:22:42Z",
    active: false
}

My understanding is that the voucher type should be an optional parameter, but it isn't nullable in the VoucherCreate class in the SDK.

Is this a bug or should I use another method to achieve this?

p-zielinski commented 1 month ago

Thank you for reporting this issue. Our findings indicate that the error is on our side, as passing the type: DISCOUNT_VOUCHER should be possible and acceptable in the case of a referral campaign. We have already prepared a fix for this bug. The issue will be resolved next week. An SDK update will not be necessary. We apologize for the inconvenience.