Creating a gift card payment provider

In this document we will provide an example of how to create a payment provider for purchasing gift cards. Functionality to deduct or add to the balance of the gift card is not included here, that will need to be added. We will also create a new Business Foundation object and tie that to the existing Contact object. With this in place we can create a gift card and assign that to a contact (customer). To be able to use the gift card payment provider we will create classes and user controls. A back-end customization and setup must also be done.

PaymentMethod

Create another user control. In this user control we will render a radio button for the Gift Card payment option. Call this user control PaymentMethod.ascx.

1. Add a reference to the assembly Mediachase.Commerce.Website.dll (IPaymentOption) in the project.

2. Inherit BaseStoreUserControl, IPaymentOption.

3. Add the following using directives:

C#

using Mediachase.BusinessFoundation.Data;
using Mediachase.BusinessFoundation.Data.Business;
using Mediachase.Commerce.Website.BaseControls;
using Mediachase.Commerce.Website;
using Mediachase.Commerce.Security;
using Mediachase.Commerce.Orders.Dto;
using Mediachase.Commerce.Orders.Managers;
using Mediachase.Commerce.Orders;
using System.Threading;

Deployment

In these steps we will deploy the GiftCardPaymentProvider assembly to the Commerce Manager and the EPiServer Commerce sites. We also deploy the user controls into specific folders.

Deploy your files by copying the GiftCardPaymentProvider to the sample project website and Commerce Manager website.

The configured system keyword of the payment provide will be GiftCard, and therefore folders with that name must be created in the Payment\Plugins folder of respectively Commerce Manage and the front end website.

Create a folder in the payment plugin folder of Commerce Manager, with the name GiftCard and put the ConfigurePayment.ascx there. The path would resolve to the following: [~CommerceManagerSite]\Apps\Order\Payments\Plugins\GiftCard\

Create a folder in sample site payment plugin folder with the name GiftCard and put the PaymentMethod.ascx there. That path would result in the following: [~Commerce SampleSite]\Templates\Sample\Units\CartCheckout\GiftCard\

Adding the gift card in Commerce Manager

Adding a business object

1. Go to Commerce Manager and Administration, navigate to the Business Foundation option, select Create New and then New Business Object.

2. Name the new object Gift Card, notice the Plural name. Leave the field info section entries to their defaults.

3. Add a new field to the Gift Card object called Amount. Note that the data type is Currency.

4. Add a new field to the Gift Card object called Balance, data type Currency.

5. Add a new field to the Gift Card object called IsActive, data type Boolean.

6. Add a new field to the Gift Card object called RedemptionCode.

7. Your Gift Card object should now look like this:

Making the gift card available

To make the gift card available to customers and to create easy management from back-end, we will use the Relationship feature another feature of Business Foundation. In order to track and record relevant data, business objects must be related to other objects, whether they are "1 to many," "many to 1","many to many."

Note that the Related Object will have the Primary Object appear under the opposite relationship (N:1) on its configuration form.

1. From the main Business Foundation menu, select the Contact object, click the tab for 1:N Relations, and then click the New Relation link in the right area of the screen.

2. Fill in the information.

3. Click the dropdown Related Object and select Gift Card. Also; Display Region should be set to Information.

4. Save your settings.

5. Click Back To List and select the Gift Card object, the N:1 tab should look like this.

Creating a payment method

In these steps we will create a new payment method by using the Gift Card object.

1. In Commerce Manager/Administration, navigate to the folder for the language of choice, for instance English (United States).

2. Click New and enter information as follows: (remember to switch to Markets tab, then select markets that this payment should be available on)

3. When done click OK.

4. Open up the new Payment Method again and go to the Parameters tab to enter GiftCard.

5. Click OK to finalize.

6. Navigate to the customer management section and select Contacts, open up the contact admin and give admin an instance of the newly created Gift Card. The Gift Card is found under the Information section, as we choose that during the setup of the relation between Contact and Gift Card objects.

7. Click Add Items and then New. Enter values as the image below

Verifying the result

Browse to the EPiServer Commerce site and login as admin. Purchase an item and when you reach the Payment Page in the Checkout wizard select the Gift Card payment and also select the child instance radio button.