Skip to content

Latest commit

 

History

History
214 lines (166 loc) · 4.18 KB

MIGRATION.md

File metadata and controls

214 lines (166 loc) · 4.18 KB

Voucherify JS SDK Migration guide

🔖 Table of contents

Migration to version 2.x

Core change in version 2.x was using async methods instead of sync versions. Sync API methods became deprecated, and will be removed in the future. Therefore breaking changes were introduced in this SDK, so that new API methods are used instead of the old ones.

The following methods return now only the async_action_id field, instead of the response with the results:

  • Vouchers bulkUpdate (additional breaking change: obligatory 'metadata' field in VouchersBulkUpdateObject)
  • Vouchers bulkUpdateMetadata (additional breaking change: obligatory 'metadata' field in VouchersBulkUpdateMetadata)
  • Products bulkUpdate
  • Products bulkUpdateMetadata (additional breaking change of the method name)

In order to get the final results, one needs to fetch it using the API method for getting the async-action result. Using the SDK method it would look like:

voucherify.asyncActions.get(async_action_id)
	.then(response => {
		console.log('Status: ', response.status);
		if (result.status === "DONE") {
			console.log('Result: ', response.result);
		}
	})

Additionally, there is a breaking change in getSku method params. New API method is used, where ID of the product is no longer required.

Migration from Voucherify Node.js SDK

Case Previously Currently
Initialization
const voucherifyClient = require('voucherify')

const client = voucherifyClient({
	applicationId: 'YOUR-APPLICATION-ID',
	clientSecretKey: 'YOUR-CLIENT-SECRET-KEY',
})
const { VoucherifyServerSide } = require('@voucherify/sdk')

const client = VoucherifyServerSide({
	applicationId: 'YOUR-APPLICATION-ID',
	secretKey: 'YOUR-SECRET-KEY',
})
Callbacks
client.vouchers.get('v1GiJYuuS', (error, result) => {
	if (error) {
		// handle error
		return
	}

	// do the work
})
Dropped support for callbacks, use promises instead
Validate Validation Rules
client.validationRules.validate(validationRuleId)
Dropped support
Loyalties Redeem Reward
client.loyalties.redeemReward(campaignId, memberId, reward)

Order required

client.loyalties.redeemReward(campaignId, memberId, reward, order)
Case Previously Currently
Initialization
$(function () {
	Voucherify.initialize('CLIENT-APPLICATION-ID', 'CLIENT-SECRET-KEY')
})
const { VoucherifyClientSide } = require('@voucherify/sdk')

const client = VoucherifyClientSide({
	clientApplicationId: 'CLIENT-APPLICATION-ID',
	clientSecretKey: 'CLIENT-SECRET-KEY',
})
Initialization - Base URL
$(function () {
	Voucherify.setBaseUrl('https://<region1>.api.voucherify.io')
})
const client = VoucherifyClientSide({
	clientApplicationId: 'CLIENT-APPLICATION-ID',
	clientSecretKey: 'CLIENT-SECRET-KEY',
	apiUrl: 'https://<region1>.api.voucherify.io',
})
Callbacks
client.validate(params, function callback(response) {})
Dropped support for callbacks for all client-side methods, use promises instead
client.validate(params).then(console.log).catch(console.log)