1.0.7 • Published 6 years ago

dotpay_widget v1.0.7

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

Dotpay widget

npm version

This is unofficial interactive widget which allows you to choose payment channel in user-friendly way if you use Dotpay payments in your shop. You can you as much widgets on one page as you want. This widget allows you also to register your own event handler on choose payment channel.

Installation

You can download the latest version or clone the repository:

git clone https://github.com/tbajorek/dotpay-widget.git

You can compile the project using npm and webpack:

npm install
npm start

You can copy later the widget.js file to your expected destnation.

Usage

At first you have to include script with Dotpay widget:

<script type="text/javascript" src="<SCRIPT_FOLDER>/widget.js"></script>

where <SCRIPT_FOLDER> contains Javascript file widget.js with code.

You can use then global object window.dotpayWidget with two methods:

  • init(configuration) - initializes a new widget according to configuration given by the configuration variable in parameter; if you don't give there some properties, they will be initialized by default values; returns jQuery object containing widget container in DOM structure;
  • getChannel() - returns details of selected channel, compatible to structure in data source; if none then it returns null.

If you don't give the configuration parameter to init() function, it still can use configuration object saved in window.dotpayConfig variable.

HTML element with class given in view.widgetContainer property has to exist when window.dotpayWidget.init() function is executed. For more details look at Examples

When you have chosen a payment channel, all channels slides up. If you want to display them again, you have to click the chosen channel.

Configuration

This table contains all values you can set in widget configuration.

PropertyTypeDescriptionDefault value
payment.sellerIdintSeller id from Dotpay panelnull
payment.amountdoubleAmount of money1000.00
payment.currencystringCode of currencyPLN
payment.langstringCode of languagepl
request.hoststringHost of request where is available data with payment channelssee more details
request.testbooleanFlag if test mode is usedfalse
request.disabledstringValue which informs how mode of displaying disabled channels is active (see more details)mark
request.hiddenChannelsarrayArray of channel numbers which will not be displayed. This feature doesn't depend on data from servernull
request.groupsarrayArray of channel group ids which are displayed. If none is specified, channels from all groups will be displayed.null
view.widgetContainerstringClass name of widget containerdotpay-widget-container
view.channelContainerstringClass name of single channel containerdotpay-channel
view.errorContainerstringClass name of error containerdotpay-widget-error
view.chosenContainerstringClass name of container for chosen channeldotpay-chosen-container
view.toggleStylestringName of style how should be toggle channels (available values: fade or slide)fade
view.informationbooleanFlag if message information should be displayed in channeltrue
event.onLoadfunctionHandler of 'load widget' event (see more details)empty function
event.onChoosefunctionHandler of 'select channel' event (see more details)empty function

Location of data source

Dotpay offers to have a test account where you can make fake payments to test your integration before switch it to production mode. Widget uses different location of data source:

  • test mode: https://ssl.dotpay.pl/test_payment/payment_api/v1/channels/
  • production mode: https://ssl.dotpay.pl/t2/payment_api/v1/channels/

You can use own data source. It requires to have available JSON data which format is compatible with used by Dotpay.

Displaying of disabled channels

Some channels can be marked in data source as disabled. You can decide how to display those channels. Here are available three ways:

  • display - disabled channel is displayed like other normal channels;
  • mark - disabled channel is displayed but marked as disable channel;
  • hide - disabled channel isn't displayed.
Handlers

Widget allows to use two handlers. They are functions which get one parameter. Handlers handles following events:

  • onLoad - widget has been loaded successfully; parameter contains data of all channels loaded from data source; the structure is the same as in the source;
  • onChoose - payment channel has been chosen by user; parameter contains jQuery event details.

Events

This widget offers two types of events: loading of its data from Dotpay server and choosing selected channel. Handlers are functions which take one argument - event data. It's the same object as for handlers given to native JavaScript function.

onLoad

The event is executed on the main widget object so its reference is given in the argument of handler.

onChoose

This event is executed when a payment channel has been selected. Single argument of its handler has additional property e.channel where is located data of selected channel with information compatible with data source (this is when e is the name of handler parameter).

Elements of e.channel object are described in this table:

PropertyTypeDescription
idintPayment channel id
namestringName of channel
logostringUrl of payment channel's logo
groupstringGroup of channel
group_namestringGroup name of channel
short_namestringSimplified name of channel
is_disablebooleanBoolean flag if channel is disabled by Dotpay
is_not_onlinebooleanBoolean flag if channel is not online (not automatical payment)
warranty_availablebooleanBoolean flag about warranty availability

Examples

Full simple code

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Dotpay Widget</title>
        <script src="../dist/widget.js"></script>
        <script>
        var dotpayConfig = {
            //widget configuration
        };
        window.dotpayWidget.jQuery(document).ready(function(){
            window.dotpayWidget.init(dotpayConfig);
        });
        </script>
    </head>
    <body>
        <div class="dotpay-widget-container"></div>
    </body>
</html>

Basic configuration

var dotpayConfig = {
	payment: {
		sellerId: 999999,
		amount: 159.47,
		currency: 'USD',
		lang: 'en'
	}
};
window.dotpayWidget.init(dotpayConfig);

License

MIT, see LICENSE file.

1.0.7

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago