1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* if you want to implement rules around selecting |
5
|
|
|
* specific payment gateways for specific orders then |
6
|
|
|
* you need to extend this class and add the following to |
7
|
|
|
* mysite/_config/config.yml: |
8
|
|
|
* <code yml> |
9
|
|
|
* Injector: |
10
|
|
|
* EcommercePaymentSupportedMethodsProvider: |
11
|
|
|
* class: MyCustom_EcommercePaymentSupportedMethodsProvider |
12
|
|
|
* </code>. |
13
|
|
|
* |
14
|
|
|
* in PHP you will have something like this: |
15
|
|
|
* <code php> |
16
|
|
|
* class MyCustom_EcommercePaymentSupportedMethodsProvider extends EcommercePaymentSupportedMethodsProvider { |
17
|
|
|
* //.... |
18
|
|
|
* } |
19
|
|
|
* </code> |
20
|
|
|
*/ |
21
|
|
|
class EcommercePaymentSupportedMethodsProvider extends Object implements EcommercePaymentSupportedMethodsProviderInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* this method returns an associative array of payment methods |
25
|
|
|
* available for the current order. |
26
|
|
|
* |
27
|
|
|
* @return array |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
public function SupportedMethods($order = null) |
30
|
|
|
{ |
31
|
|
|
$hideTestPaymentMethods = false; |
32
|
|
|
if (Director::isLive()) { |
33
|
|
|
$hideTestPaymentMethods = true; |
34
|
|
|
} |
35
|
|
|
$supportedMethods = EcommerceConfig::get('EcommercePayment', 'supported_methods'); |
36
|
|
|
if (ArrayLib::is_associative($supportedMethods)) { |
37
|
|
|
if ($hideTestPaymentMethods) { |
38
|
|
|
if (count($supportedMethods)) { |
39
|
|
|
foreach ($supportedMethods as $methodClass => $methodTitle) { |
|
|
|
|
40
|
|
|
if (is_subclass_of($methodClass, 'EcommercePayment_Test')) { |
41
|
|
|
unset($supportedMethods[$methodClass]); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} else { |
47
|
|
|
user_error('EcommercePayment::$supported_methods() requires an associative array. Right now the supported payments methods are: '.print_r($supportedMethods, 1), E_USER_NOTICE); |
48
|
|
|
} |
49
|
|
|
return $supportedMethods; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function assign_payment_gateway($gateway = "") |
53
|
|
|
{ |
54
|
|
|
user_error(" |
55
|
|
|
This function has not been implemented on this class. |
56
|
|
|
You can extend this class to allow for a supported method to be set."); |
57
|
|
|
} |
58
|
|
|
/** |
59
|
|
|
* returns the order to use.... |
60
|
|
|
* You can provide one as a param, |
61
|
|
|
* which basically just checks that it is a real order. |
62
|
|
|
* |
63
|
|
|
* @param Order (optional) | Int |
|
|
|
|
64
|
|
|
* |
65
|
|
|
* @return Order |
|
|
|
|
66
|
|
|
*/ |
67
|
|
|
protected function orderToUse($order = null) |
68
|
|
|
{ |
69
|
|
|
if ($order && $order instanceof Order) { |
70
|
|
|
return $order; |
71
|
|
|
} |
72
|
|
|
if (intval($order)) { |
73
|
|
|
return Order::get()->byID(intval($order)); |
74
|
|
|
} else { |
75
|
|
|
return ShoppingCart::current_order(); |
76
|
|
|
} |
77
|
|
|
user_error("Can't find an order to use"); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.