Does BV Commerce support ________ payment gateway?
We hear this question all of the time. While BV Commerce does support a lot of credit card payment gateways out-of-the-box it doesn't support every one. Fortunately we provide an easy-to-use plugin architecture for developers to create new payment gateway integrations. In this article we'll walk through the plugin architecture and how to leverage it for your integration.
Payment Gateway Class
Create a new class in the /App_Code folder of your website using the name of your payment gateway. The class should inherit from BVSoftware.Bvc5.Payment.CCPaymentBase. Download a commented example of what your class should look like. Note that you will need to add the code specific to your payment gateway integration.
There are two string properties that your class must override:
GatewayId should return a GUID string that you generate; do not use the GUID value from the sample code. The GatewayName property should return the 'friendly' name of your gateway.
There are five Boolean functions that you must override in your class that are used to tell the system what functionality your gateway integration supports. They are:
- SupportsAuthorize
- SupportsCapture
- SupportsCharge
- SupportsRefund
- SupportsVoid
These functions should simply return True or False depending on what your gateway integration supports.
Lastly your class must override the ProcessCard function, which is where all of the magic happens. This function takes a string parameter called chargeType which should accept the following single-character values:
- "A" (pre-authorize)
- "P" (post-authorize)
- "S" (sale/charge)
- "V" (void)
- "C" (credit)
Your function should perform the proper transaction with the payment gateway based on the chargeType value.
Admin Settings
With the integration coding complete we must create an admin interface for merchants to configure the payment gateway settings. Start by creating a folder in the /BVModules/CreditCardGateways/ folder with exactly the same name as the GatewayName property of your class (including spaces). Inside this folder create an Edit.ascx user control that inherits from BVSoftware.Bvc5.Core.Content.BVModule. Typical settings that you might store are things like:
- Test/Debug Mode (Boolean)
- Username (string)
- Password (string)
- Gateway URL
Use the SettingsManager property of your user control class (available since you're inheriting from the BVModule class) to load and save settings. SettingsManager has helper functions which handle encrypting and decrypting data (to securely store things like passwords) as well as functions for working with integers, decimals, and Boolean values so you don't have to cast them. You may have noticed the sample code linked above shows how to retrieve these settings in your payment gateway class. To see a completed example of an Edit.ascx user control for a payment gateway take a look at the Authorize.Net control at /BVModules/CreditCardGateways/Authorize.Net/Edit.ascx.
Wiring It Up
The last step is to tell BV Commerce about your new payment gateway so you can configure it via the admin. To do this you must edit the TaskLoader.Custom.vb class in the /App_Code folder. Find the LoadCustomCreditCardGateways subroutine. You will need to add a new instance of your payment gateway class to the result collection of CreditCardGateway objects. Your code should look something like this:
result.Add(New NewGateway())
That's it! You should now be able to select your payment gateway in the admin. Go to the Options >> Payment page and click the Edit button next to Credit Card. You should see your gateway listed in the Gateway dropdown box at the bottom of the page. Select it and click the Edit button to configure the settings on the Edit.ascx control that you created.