Functionality to deduct from or add to the gift card balance is not included here - that must be added.
You also create a new Business Foundation object and tie that to the existing Contact object. With this in place, you can create a gift card and assign it to a contact (customer). To use the gift card payment provider, you create classes and user controls. You must also complete a back-end customization and set it up.
Classes in this topic are available in the Mediachase.Commerce.Orders namespace.
To use the payment gateway in serializable cart mode, it must implement IPaymentPlugin, which is similiar to IPaymentGateway. However, IPaymentPlugin takes an IShipment instead of a Shipment. It is possible to implement both IPaymentPlugin and IPaymentGateway in one class.
## Create classes
Create a class that implements the IPaymentGateway interface.
In Visual Studio, create a new project named **GiftCardPaymentProvider**.
Delete the _app.data_folder, the \_web.config_, and the _Default.aspx_ files, since they are not required.
From the site root, create the folder structure: this adheres to Commerce Manager.
Create a new class, GiftGateway.cs, which does the following: a. Returns the configuration data associated with a gateway. b. Sets the configuration gateway data. This data typically includes information like gateway URL, account info, and so on.
To the class, add **using Mediachase.Commerce.Orders; **Resides in Mediachase.Commerce.Orders.IPaymentGateway.
Add a reference to the _Mediachase.Commerce.dll_ assembly.
Implement the interface IPaymentGateway.
**Example: implement the payment gateway interfac**
You can ignore error messages that occur at this step.
Create a new class called GiftManager.cs (public static class GiftManager). See the following code comments.
**Example: create the GiftManager**
Build the project.
## Create user controls
Create the user controls needed for the gift card payment provider.
Create a user control called _ConfigurePayment.ascx_. This user control needs to inherit from System.Web.UI.UserControl, IGatewayControl. See the code comments in the examples.
**Example: create the ConfigurePayment user control (part 1)**
**Example: create the ConfigurePayment user control (part 2)**
Deploy the GiftCardPaymentProvider assembly to the Commerce Manager and the Customized Commerce sites. We also deploy the user controls into specific folders.
Deploy files by copying the GiftCardPaymentProvider to the sample project website and Commerce Manager website.
The configured system keyword of the payment provide is GiftCard. Therefore, folders with that name must be created in the _Payment\\Plugins_ folder of the Commerce Manager and front end website.
Create a folder in the Commerce Manager payment plugin folder with the name _GiftCard_. Put the _ConfigurePayment.ascx_ there. The path resolves to \*[~CommerceManagerSite]\\Apps\\Order\\Payments\\Plugins\\GiftCard\*
Create a folder in sample site payment plugin folder with the name _GiftCard_. Put the _PaymentMethod.ascx_ there. That path resolves to \*[~Commerce SampleSite]\\Templates\\Sample\\Units\\CartCheckout\\GiftCard\*.
## Add the gift card in Commerce Manager
### Add a business object
Go to **Commerce Manager** **> Administration **> **Business Foundation** > **Create New** > **New Business Object**.
Name the new object Gift Card, and notice the **Plural Name**. Leave the field info section entries to their defaults.
Add a new field to the Gift Card object called **Amount**. Note that the data type is **Currency**.
Add a new field to the Gift Card object called **Balance**, data type **Currency**.
Add a new field to the Gift Card object called **IsActive**, data type **Boolean**.
Add a new field to the Gift Card object called **RedemptionCode**.
Your Gift Card object should look like this.
### Make the gift card available
To make the gift card available to customers and create easy management from the back-end, use the Business Foundation (BF) Relationship feature. To track and record relevant data, business objects must be related to other objects, whether they are 1-to-many, many-to-1, or many-to-many.
The Related Object has the Primary Object appear under the opposite relationship (N:1) on its configuration form.
From the main BF menu, select the **Contact** object, click the tab for **1:N Relations**, then click the **New Relation** link in the right area of the screen.
Fill in the information.
Click the dropdown Related Object, select **Gift Card**.
Set **Display Region** to Information.
Save your settings.
Click **Back To List** and select the **Gift Card** object. The **N:1** tab should look like this.
### Create a payment method
Create a new payment method by using the Gift Card object.
In **Commerce Manager/Administration**, navigate to the folder for the language of choice, such as English (United States).
Click **New** and enter information as follows. (Remember to switch to the **Markets** tab, then select markets for which this payment should be available).
When done, click **OK**.
Open the new **Payment Method** again, go to the **Parameters** tab, and enter **GiftCard**.
Go 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. (You chose that during the setup of the relation between **Contact** and **Gift Card** objects.)
Click **Add Items** then **New**. Enter values as shown below
## Verify the result
Browse to the Commerce site and log in as an admin.
Purchase an item.
When you reach the Checkout wizard Payment Page, select **Gift Card payment**. Also, select the child instance radio button.