· 6 years ago · Nov 05, 2019, 11:10 AM
1<?php
2/**
3 * WHMCS ePay (Bambora Denmark) Module
4 * Author : Bhagwan Sahane [Logicmaker Softwares]
5 * Email : support@logicmaker.in
6 * Website : www.logicmaker.in
7 * Version : 1.1
8 * Date : 2019-01-23
9 *
10 */
11
12if (!defined("WHMCS")) {
13 die("This file cannot be accessed directly");
14}
15
16/**
17 * Define module related meta data.
18 *
19 * Values returned here are used to determine module related capabilities and
20 * settings.
21 *
22 * @see https://developers.whmcs.com/payment-gateways/meta-data-params/
23 *
24 * @return array
25 */
26function epay_MetaData()
27{
28 return array(
29 'DisplayName' => 'Bambora Online ePay',
30 'APIVersion' => '1.1', // Use API Version 1.1
31 'DisableLocalCredtCardInput' => true,
32 'TokenisedStorage' => false,
33 );
34}
35
36/**
37 * Define gateway configuration options.
38 *
39 * The fields you define here determine the configuration options that are
40 * presented to administrator users when activating and configuring your
41 * payment gateway module for use.
42 *
43 * Supported field types include:
44 * * text
45 * * password
46 * * yesno
47 * * dropdown
48 * * radio
49 * * textarea
50 *
51 * Examples of each field type and their possible configuration parameters are
52 * provided in the sample function below.
53 *
54 * @return array
55 */
56function epay_config()
57{
58 return array(
59 // the friendly display name for a payment gateway should be
60 // defined here for backwards compatibility
61 "FriendlyName" => array(
62 "Type" => "System",
63 "Value" => "Bambora Online ePay"
64 ),
65 "merchantnumber" => array(
66 "FriendlyName" => "Merchant Number",
67 "Type" => "text",
68 "Size" => "20",
69 'Default' => "",
70 "Description" => "The number identifying your ePay merchant account."
71 ),
72 "group" => array(
73 "FriendlyName" => "Group",
74 "Type" => "text",
75 "Size" => "20",
76 'Default' => "",
77 "Description" => "The group id is used for grouping payments in the ePay Administration."
78 ),
79 "md5key" => array(
80 "FriendlyName" => "MD5 Key",
81 "Type" => "text",
82 "Size" => "50",
83 'Default' => "",
84 "Description" => "The MD5 key is used to stamp data sent between WHMCS and Bambora to prevent it from being tampered with. The MD5 key is optional but if used here, must be the same as in the ePay administration."
85 ),
86 "authmail" => array(
87 "FriendlyName" => "Auth Mail",
88 "Type" => "text",
89 "Size" => "50",
90 'Default' => ""
91 ),
92 "subscriptionfee" => array(
93 "FriendlyName" => "Add fee to subscription transactions",
94 "Type" => "yesno"
95 ),
96 "captureonduedate" => array(
97 "FriendlyName" => "Wait to capture on due date",
98 "Type" => "yesno"
99 )
100 );
101}
102
103/**
104 * Payment link.
105 *
106 * Required by third party payment gateway modules only.
107 *
108 * Defines the HTML output displayed on an invoice. Typically consists of an
109 * HTML form that will take the user to the payment gateway endpoint.
110 *
111 * @param array $params Payment Gateway Module Parameters
112 *
113 * @see https://developers.whmcs.com/payment-gateways/third-party-gateway/
114 *
115 * @return string
116 */
117function epay_link($params)
118{
119 // Gateway Configuration Parameters
120 $merchantnumber = $params['merchantnumber'];
121 $authsms = $params['authsms'];
122 $authmail = $params['authmail'];
123 $group = $params['group'];
124
125 // Invoice Parameters
126 $invoiceid = $params['invoiceid'];
127 $amount = $params['amount'] * 100;
128 $currencyCode = $params['currency'];
129
130 // Client Parameters
131 $clientId = $params['clientdetails']['id'];
132
133 // System Parameters
134 $systemUrl = $params['systemurl'];
135 $returnUrl = $params['returnurl'];
136 $langPayNow = $params['langpaynow'];
137
138 $url = 'https://ssl.ditonlinebetalingssystem.dk/integration/ewindow/Default.aspx';
139
140 //Parameters is descriped here: http://tech.epay.dk/en/specification
141 $epay_params = array();
142 $epay_params["merchantnumber"] = $merchantnumber;
143 $epay_params["orderid"] = $invoiceid;
144 $epay_params["currency"] = $currencyCode;
145 $epay_params["amount"] = $amount;
146 $epay_params["accepturl"] = $returnUrl;
147 $epay_params["cancelurl"] = $systemUrl;
148 $epay_params["windowstate"] = "3";
149 $epay_params["encoding"] = "UTF-8";
150 $epay_params["callbackurl"] = $systemUrl . 'modules/gateways/callback/epay.php?clientid=' . $clientId;
151 $epay_params["subscription"] = "1";
152 $epay_params["subscriptionname"]= $clientId;
153 $epay_params["instantcallback"] = "1";
154 $epay_params["instantcapture"] = "1";
155 $epay_params["smsreceipt"] = $authsms;
156 $epay_params["mailreceipt"] = $authmail;
157 $epay_params["group"] = $group;
158
159 // http://epay.bambora.com/en/hash-md5-check
160 $epay_params["hash"] = md5(implode("", array_values($epay_params)) . $params['md5key']);
161
162 $htmlOutput = '<form action="' . $url . '" method="post">';
163 foreach ($epay_params as $key => $value)
164 {
165 $htmlOutput .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />' . "\n";
166 }
167 $htmlOutput .= '<input type="submit" class="btn btn-success" value="' . $langPayNow . '" />';
168 $htmlOutput .= '</form>';
169
170 return $htmlOutput;
171}
172
173/**
174 * Refund transaction.
175 *
176 * Called when a refund is requested for a previously successful transaction.
177 *
178 * @param array $params Payment Gateway Module Parameters
179 *
180 * @see https://developers.whmcs.com/payment-gateways/refunds/
181 *
182 * @return array Transaction response status
183 */
184function epay_refund($params)
185{
186 // Gateway Configuration Parameters
187 $merchantnumber = $params['merchantnumber'];
188
189 // Transaction Parameters
190 $transactionId = $params['transid'];
191 $amount = $params['amount'];
192
193 $epay_params = array();
194 $epay_params['merchantnumber'] = $merchantnumber;
195 $epay_params['transactionid'] = $transactionId;
196 $epay_params['amount'] = $amount * 100;
197 $epay_params['pbsresponse'] = -1;
198 $epay_params['epayresponse'] = -1;
199
200 $soap = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL', array("trace" => 1, "exceptions" => 0));
201 $soap_credit_result = $soap->credit($epay_params);
202 logActivity($soap->__getLastRequest());
203 logActivity($soap->__getLastRequestHeaders());
204 logActivity('ePay2 ' . $soap->__getLastResponse());
205
206 if($soap_credit_result->creditResult == true)
207 {
208 return array("status" => "success", "transid" => $transactionId, "rawdata" => $soap_credit_result);
209 }
210 elseif ($soap_credit_result->creditResult == false)
211 {
212 return array("status" => "declined", "rawdata" => $soap_credit_result);
213 }
214 else
215 {
216 return array("status" => "error", "rawdata" => $soap_credit_result);
217 }
218}
219?>