|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverShop\Checkout\Step; |
|
4
|
|
|
|
|
5
|
|
|
use SilverShop\Cart\ShoppingCart; |
|
6
|
|
|
use SilverShop\Checkout\Checkout; |
|
7
|
|
|
use SilverShop\Checkout\CheckoutComponentConfig; |
|
8
|
|
|
use SilverShop\Checkout\Component\Payment; |
|
9
|
|
|
use SilverShop\Forms\CheckoutForm; |
|
10
|
|
|
use SilverStripe\Forms\FieldList; |
|
11
|
|
|
use SilverStripe\Forms\FormAction; |
|
12
|
|
|
use SilverStripe\Omnipay\GatewayInfo; |
|
13
|
|
|
|
|
14
|
|
|
class PaymentMethod extends CheckoutStep |
|
15
|
|
|
{ |
|
16
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
17
|
|
|
'paymentmethod', |
|
18
|
|
|
'PaymentMethodForm', |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
protected function checkoutconfig() |
|
22
|
|
|
{ |
|
23
|
|
|
$config = CheckoutComponentConfig::create(ShoppingCart::curr(), false); |
|
24
|
|
|
$config->addComponent(Payment::create()); |
|
25
|
|
|
|
|
26
|
|
|
return $config; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function paymentmethod() |
|
30
|
|
|
{ |
|
31
|
|
|
$gateways = GatewayInfo::getSupportedGateways(); |
|
32
|
|
|
if (count($gateways) == 1) { |
|
33
|
|
|
return $this->owner->redirect($this->NextStepLink()); |
|
34
|
|
|
} |
|
35
|
|
|
return [ |
|
36
|
|
|
'OrderForm' => $this->PaymentMethodForm(), |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function PaymentMethodForm() |
|
41
|
|
|
{ |
|
42
|
|
|
$form = CheckoutForm::create($this->owner, 'PaymentMethodForm', $this->checkoutconfig()); |
|
43
|
|
|
$form->setActions( |
|
44
|
|
|
FieldList::create( |
|
45
|
|
|
FormAction::create('setpaymentmethod', _t('SilverShop\Checkout\Step\CheckoutStep.Continue', 'Continue')) |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
$this->owner->extend('updatePaymentMethodForm', $form); |
|
49
|
|
|
|
|
50
|
|
|
return $form; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setpaymentmethod($data, $form) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
$this->checkoutconfig()->setData($form->getData()); |
|
56
|
|
|
return $this->owner->redirect($this->NextStepLink()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function SelectedPaymentMethod() |
|
60
|
|
|
{ |
|
61
|
|
|
return Checkout::get($this->owner->Cart())->getSelectedPaymentMethod(true); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|