1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bummzack\SsOmnipayUI\GridField; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
6
|
|
|
use SilverStripe\Control\HTTPRequest; |
7
|
|
|
use SilverStripe\Forms\GridField\GridField; |
8
|
|
|
use SilverStripe\Forms\GridField\GridField_URLHandler; |
9
|
|
|
use SilverStripe\Omnipay\Model\Payment; |
10
|
|
|
use SilverStripe\ORM\DataObject; |
11
|
|
|
use SilverStripe\View\ArrayData; |
12
|
|
|
use SilverStripe\View\Requirements; |
13
|
|
|
use SilverStripe\View\SSViewer; |
14
|
|
|
|
15
|
|
|
class GridFieldPaymentStatusIndicator extends GridFieldPaymentAction implements GridField_URLHandler |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
* @param GridField $gridField |
20
|
|
|
* @param DataObject $record |
21
|
|
|
* @param string $columnName |
22
|
|
|
* @return string|null - the HTML for the column |
23
|
|
|
*/ |
24
|
|
|
public function getColumnContent($gridField, $record, $columnName) |
25
|
|
|
{ |
26
|
|
|
if (!($record instanceof Payment)) { |
27
|
|
|
return null; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
Requirements::css('bummzack/silverstripe-omnipay-ui: client/dist/css/omnipay-ui-cms.css'); |
31
|
|
|
Requirements::javascript('bummzack/silverstripe-omnipay-ui: client/dist/javascript/omnipay-ui-cms.js'); |
32
|
|
|
|
33
|
|
|
if (preg_match('/Pending(Capture|Void|Refund)/', $record->Status)) { |
34
|
|
|
return SSViewer::execute_template('PaymentPendingIndicator', ArrayData::create(array( |
35
|
|
|
'StatusLink' => Controller::join_links($gridField->Link('checkPaymentPending')), |
36
|
|
|
'PaymentID' => $record->ID, |
37
|
|
|
'Timeout' => 2000 |
38
|
|
|
))); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return null; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getURLHandlers($gridField) |
45
|
|
|
{ |
46
|
|
|
return array( |
47
|
|
|
'checkPaymentPending' => 'handleCheckPaymentPending' |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Accepts a list of ids in form of comma separated string via GET parameter. If any of these payments is no longer |
53
|
|
|
* pending, this method returns true, false otherwise. |
54
|
|
|
* @param $gridField |
55
|
|
|
* @param HTTPRequest|null $request |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function handleCheckPaymentPending($gridField, HTTPRequest $request = null) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
if (!$request) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$ids = preg_split('/[^\d]+/', $request->getVar('ids')); |
65
|
|
|
return Payment::get() |
66
|
|
|
->filter('ID', $ids) |
67
|
|
|
->exclude('Status', array('PendingVoid', 'PendingCapture', 'PendingRefund')) |
68
|
|
|
->count() > 0; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.