-
Notifications
You must be signed in to change notification settings - Fork 1
/
j06000example_payment_gateway_callback.class.php
executable file
·132 lines (106 loc) · 4.25 KB
/
j06000example_payment_gateway_callback.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Core file.
*
* @author Vince Wooll <sales@jomres.net>
*
* @version Jomres 10.2.2
*
* @copyright 2005-2022 Vince Wooll
* Jomres (tm) PHP, CSS & Javascript files are released under both MIT and GPL2 licenses. This means that you can choose the license that best suits your project, and use it accordingly
**/
// ################################################################
defined('_JOMRES_INITCHECK') or die('');
// ################################################################
/**
* @package Jomres\Core\Minicomponents
*
*
*/
class j06000bitpay_callback
{
/**
*
* Constructor
*
* Main functionality of the Minicomponent
*
*
*
*/
public function __construct()
{
// Must be in all minicomponents. Minicomponents with templates that can contain editable text should run $this->template_touch() else just return
$MiniComponents = jomres_singleton_abstract::getInstance('mcHandler');
if ($MiniComponents->template_touch) {
$this->template_touchable = false;
return;
}
$plugin="example_payment_gateway";
// This holds the booking's details. In Jomres the
$tmpBookingHandler =jomres_getSingleton('jomres_temp_booking_handler');
$ePointFilepath = get_showtime('ePointFilepath');
$settingArray = [];
$query = "SELECT setting,value FROM #__jomres_pluginsettings WHERE prid = ".$tmpBookingHandler->tmpbooking['property_uid']." AND plugin = '".$plugin."' ";
$settingsList = doSelectSql( $query );
if ( count ($settingsList) > 0) {
foreach ( $settingsList as $set ) {
$settingArray[ $set->setting ] = trim($set->value);
}
}
$test_mode = false;
$api_token = trim($settingArray[ 'api_token' ]); // Copy pasta from browsers can introduce spaces
if ( $settingArray[ 'test_mode' ] == '1' ) {
$test_mode = true;
$api_token = trim($settingArray[ 'test_api_token' ]);
}
// Try to fall back to test mode
if ( $settingArray[ 'api_token' ] == '' ) {
$test_mode = true;
$api_token = trim($settingArray[ 'test_api_token' ]);
}
if ( $test_mode && $settingArray[ 'test_api_token' ] =='' ) {
$test_mode = true;
}
if ($test_mode) {
$resourceUrl = 'https://test.test.com/invoices';
} else {
$resourceUrl = 'https://www.test.com/invoices';
}
// Here we will call the gateway back using the invoice id that was stored at the end of the 00605 script to confirm successful payment
$curlCli = curl_init($resourceUrl . '/' . $tmpBookingHandler->tmpbooking['example_gateway_invoice_id']. '?token=' . $api_token);
curl_setopt($curlCli, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curlCli, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlCli, CURLOPT_HTTPHEADER, [
'X-Accept-Version: 2.0.0',
'Content-Type: application/json'
]);
$result = curl_exec($curlCli);
$resultData = json_decode($result, TRUE);
curl_close($curlCli);
// If the gateway service confirms that the deposit has been paid then we will go ahead and insert the booking. This is your end goal.
if ( $resultData['data']['status'] == 'paid' || $resultData['data']['status'] == 'confirmed' || $resultData['data']['status'] == 'complete') {
insertInternetBooking(get_showtime('jomressession'),true,true);
} else {
property_header($tmpBookingHandler->tmpbooking['property_uid']);
$booking_form_url = get_booking_url($tmpBookingHandler->tmpbooking['property_uid']);
$pageoutput = [];
$output = [];
// If available you could provide more information as to why the payment failed
$output['EXAMPLE_GATEWAY_PAYMENT_FAILED']=jr_gettext('EXAMPLE_GATEWAY_PAYMENT_FAILED', 'EXAMPLE_GATEWAY_PAYMENT_FAILED', false);
$output['EXAMPLE_GATEWAY_PAYMENT_FAILED_BLURB']=jr_gettext('EXAMPLE_GATEWAY_PAYMENT_FAILED_BLURB', 'EXAMPLE_GATEWAY_PAYMENT_FAILED_BLURB', false);
$output['EXAMPLE_GATEWAY_PAYMENT_FAILED_BUTTON']=jr_gettext('EXAMPLE_GATEWAY_PAYMENT_FAILED_BUTTON', 'EXAMPLE_GATEWAY_PAYMENT_FAILED_BUTTON', false);
$output['BOOKING_FORM_URL'] = $booking_form_url ;
$pageoutput[]=$output;
$tmpl = new patTemplate();
$tmpl->setRoot( $ePointFilepath.'templates'.JRDS.find_plugin_template_directory() );
$tmpl->readTemplatesFromInput( 'payment_failed.html');
$tmpl->addRows( 'pageoutput',$pageoutput);
$tmpl->displayParsedTemplate();
}
}
public function getRetVals()
{
return null;
}
}