Send a Voucher
Setup the Create Config
In order to send Vouchers you need to setup a create configuration.
CreateConfiguration createConfiguration = new CreateConfiguration.Builder(context)
.setGiftItems(
new TipPersonalizationOption(context),
new TitlePersonalizationOption(),
new ToPersonalizationOption(),
new NotePersonalizationOption(),
new WrappingPaperPersonalizationOption(),
new ImagePersonalizationOption().setGoogleImagesEnabled(false),
new GiftCardPersonalizationOption(),
new VideoPersonalizationOption().enableYouTube(false),
new AudioPersonalizationOption())
.build();
val createConfiguration = CreateConfiguration.Builder(context)
.setGiftItems(
TipPersonalizationOption(context),
TitlePersonalizationOption(),
ToPersonalizationOption(),
NotePersonalizationOption(),
WrappingPaperPersonalizationOption(),
ImagePersonalizationOption().setGoogleImagesEnabled(false),
GiftCardPersonalizationOption(),
VideoPersonalizationOption().enableYouTube(false),
AudioPersonalizationOption())
.build()
Then add it to your VouchrEngine
engineBuilder.setCreateConfig(createConfiguration);
engineBuilder.setCreateConfig(createConfiguration)
In order to actually send vouchers users need to be authenticated with Vouchrs server. This is done using an AuthLoginManager
.
For nonproduction sandbox usage a JWT example can be seen here: JWTExample.
AuthManager authManager = new JWTAuthManager();
val authManager = JWTAuthManager()
Then add your auth to the engine.
Putting it all together it should look something like this:
AuthManager authManager = new SimpleAuthManager();
Engine engine = new Engine.Builder(VOUCHR_BASE_URL, SDK_ID)
.setCreateConfig(createConfiguration)
.addAuthManager(authManager)
.build();
engine.startup(this);
val authManager = SimpleAuthManager()
val engine = Engine.Builder(VOUCHR_BASE_URL, SDK_ID)
.setCreateConfig(createConfiguration)
.addAuthManager(authManager)
.build()
engine.startup(this)
Some additional work to set up the AuthManager in the above snippet needs to be done - see here for details.
Launch the Create Flow
To start the create flow you just need use the following IntentBuilder.
VoucherCreationActivity.IntentBuilder.init().start(this);
VoucherCreationActivity.IntentBuilder.init().start(this)
Launching Create with Prepopulated Data
Sometimes you need/want to start the create flow with some images, videos, a recipient, etc. You can do this using the IntentBuilder
mentioned above.
Here’s an example:
VoucherCreationActivity.IntentBuilder.init()
.addTitle("An amazing gift")
.addWrappingPaper(wrappingPapper)
.addDate(openDate)
.setContestMode(true)
.addImage("imageUrl")
.addSound("soundUrl")
.addNote("Note text")
.start(this);
VoucherCreationActivity.IntentBuilder.init()
.addTitle("An amazing gift")
.addWrappingPaper(wrappingPapper)
.addDate(openDate)
.setContestMode(true)
.addImage("imageUrl")
.addSound("soundUrl")
.addNote("Note text")
.start(this)
Control where to go after creation
Here is an example opening a custom activity at the end of create.
CreateConfiguration createConfiguration = new CreateConfiguration.Builder(context)
...
.setCreateFlowController(new CreateFlowController.Default() {
@Override
public void onCreateFinished(Activity activity, long voucherId) {
super.onCreateFinished(activity, voucherId);
new GiftUrlActivity.IntentBuilder().setVoucherId(voucherId).start(activity);
}
})
.build();
val createConfiguration = CreateConfiguration.Builder(context)
...
.setCreateFlowController(object : CreateFlowController.Default() {
override fun onCreateFinished(activity : Activity, voucherId : Long) {
super.onCreateFinished(activity, voucherId)
GiftUrlActivity.IntentBuilder().setVoucherId(voucherId).start(activity)
}
})
.build()
Here is an example logging when a user manually cancels the create flow
CreateConfiguration createConfiguration = new CreateConfiguration.Builder(context)
...
.setCreateFlowController(new CreateFlowController.Default() {
@Override
public void onCreateCanceled() {
super.onCreateCanceled();
Log.d(TAG, "Create Canceled");
}
})
.build();
val createConfiguration = CreateConfiguration.Builder(context)
...
.setCreateFlowController(object : CreateFlowController.Default() {
override fun onCreateCanceled() {
super.onCreateCanceled()
Log.d(TAG, "Create Canceled")
}
})
.build()
Getting a Claim URL
Use the following method to generate a URL used to view a Voucher:
VoucherSDK.giftManager().getShareUrl(voucherId);
VoucherSDK.giftManager().getShareUrl(voucherId)
This method can only be called after a gift has been activated. *Note: This url can be used to claim a gift