Hide menu Last updated: Oct 24 2016
Area: Episerver Commerce Applies to versions: 10 and higher
Other versions:

Creating a gift card payment provider

This topic explains how to create a payment provider for purchasing gift cards in Episerver Commerce. Functionality to deduct or add to the balance of the gift card 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 that 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.

Creating classes

Create a class that implements the IPaymentGateway interface.

  1. In Visual Studio, create a new project named GiftCardPaymentProvider.
  2. Delete the app.data folder, the web.config, and the Default.aspx files since they are not required.
  3. From the root of the site, create the folder structure: this adheres to Commerce Manager.
  4. Create a new class called GiftGateway.cs, which does the following:
    1. Returns the configuration data associated with a gateway.
    2. Sets the configuration gateway data. This data typically includes information like gateway URL, account info, and so on.
  5. To the class, add: using Mediachase.Commerce.Orders; Resides in Mediachase.Commerce.Orders.IPaymentGateway.
  6. Add a reference to the Mediachase.Commerce.dll assembly.
  7. Implement the interface IPaymentGateway.

    Note : You can ignore error messages that occur at this step.

  8. Create a new class called GiftManager.cs (public static class GiftManager). See the following code comments.

9. Build the project.

Creating user controls

Create the user controls needed for the gift card payment provider.

ConfigurePayment

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.

Deployment

Deploy the GiftCardPaymentProvider assembly to the Commerce Manager and the Episerver Commerce sites. We also deploy the user controls into specific folders.

  1. Deploy files by copying the GiftCardPaymentProvider to the sample project website and Commerce Manager website.
  2. The configured system keyword of the payment provide is GiftCard. Therefore, folders with that name must be created in the Payment\Plugins folder of respectively Commerce Manage and the front end website.
  3. Create a folder in the Commerce Manager payment plugin folder with the name GiftCard. Put the ConfigurePayment.ascx there. The path resolves to the following: [~CommerceManagerSite]\Apps\Order\Payments\Plugins\GiftCard\
  4. Create a folder in sample site payment plugin folder with the name GiftCard. Put the PaymentMethod.ascx there. That path resolves to 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 > Administration > Business Foundation > Create New > New Business Object.
  2. Name the new object Gift Card, and 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 look like this.

Making the gift card available

To make the gift card available to customers and to 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.

Note: The Related Object has the Primary Object appear under the opposite relationship (N:1) on its configuration form.

  1. 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.
  2. Fill in the information.
  3. Click the dropdown Related Object, select Gift Card. Also, set Display Region 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

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, such as English (United States).
  2. Click New and enter information as follows. (Remember to switch to the Markets tab, then select markets for which this payment should be available).
  3. When done, click OK.
  4. Open the new Payment Method again, go to the Parameters tab, and enter GiftCard.
  5. Click OK.
  6. Go to the customer management section and select Contacts,
  7. 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.)
  8. Click Add Items then New. Enter values as shown below

Verifying the result

  1. Browse to the Episerver Commerce site and log in as an admin.
  2. Purchase an item.
  3. When you reach the Checkout wizard Payment Page, select Gift Card payment. Also, select the child instance radio button.

Comments