1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Checkout\PaymentMethods; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverSelect; |
6
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
7
|
|
|
use Magium\Magento\Actions\Checkout\PaymentInformation; |
8
|
|
|
use Magium\Magento\Identities\Customer; |
9
|
|
|
use Magium\WebDriver\WebDriver; |
10
|
|
|
|
11
|
|
|
class SagePay implements PaymentMethodInterface |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
const ACTION = 'Checkout\PaymentMethods\SagePay'; |
15
|
|
|
|
16
|
|
|
protected $webDriver; |
17
|
|
|
protected $testCase; |
18
|
|
|
protected $paymentInformation; |
19
|
|
|
protected $customer; |
20
|
|
|
protected $assertion; |
21
|
|
|
|
22
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
23
|
|
|
WebDriver $webDriver, |
24
|
|
|
AbstractMagentoTestCase $testCase, |
25
|
|
|
PaymentInformation $paymentInformation, |
26
|
|
|
Customer $customer, |
27
|
|
|
\Magium\Magento\Assertions\Checkout\PaymentMethods\SagePay $assertion |
28
|
|
|
) { |
29
|
|
|
$this->webDriver = $webDriver; |
30
|
|
|
$this->testCase = $testCase; |
31
|
|
|
$this->paymentInformation = $paymentInformation; |
32
|
|
|
$this->customer = $customer; |
33
|
|
|
$this->assertion = $assertion; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getId() |
37
|
|
|
{ |
38
|
|
|
return 'p_method_sagepaydirectpro'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function pay($requirePayment) |
42
|
|
|
{ |
43
|
|
|
if ($requirePayment) { |
44
|
|
|
$this->testCase->assertElementExists($this->getId()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
if (!$this->webDriver->elementDisplayed('sagepaydirectpro_cc_owner')) { |
|
|
|
|
48
|
|
|
$this->webDriver->getMouse()->click($this->webDriver->byId($this->getId())->getCoordinates()); |
49
|
|
|
} |
50
|
|
|
$this->assertion->assert(); |
51
|
|
|
|
52
|
|
|
$select = new WebDriverSelect($this->webDriver->byId('sagepaydirectpro_cc_type')); |
53
|
|
|
$select->selectByValue($this->paymentInformation->getType()); |
54
|
|
|
|
55
|
|
|
$this->webDriver->byId('sagepaydirectpro_cc_number')->clear(); |
56
|
|
|
$this->webDriver->byId('sagepaydirectpro_cc_number')->sendKeys($this->paymentInformation->getCreditCardNumber()); |
57
|
|
|
|
58
|
|
|
$select = new WebDriverSelect($this->webDriver->byId('sagepaydirectpro_expiration')); |
59
|
|
|
$select->selectByValue($this->paymentInformation->getExpiryMonth()); |
60
|
|
|
|
61
|
|
|
$select = new WebDriverSelect($this->webDriver->byId('sagepaydirectpro_expiration_yr')); |
62
|
|
|
$select->selectByValue($this->paymentInformation->getExpiryYear()); |
63
|
|
|
|
64
|
|
|
$this->webDriver->byId('sagepaydirectpro_cc_cid')->clear(); |
65
|
|
|
$this->webDriver->byId('sagepaydirectpro_cc_cid')->sendKeys($this->paymentInformation->getCvv()); |
66
|
|
|
|
67
|
|
|
$this->webDriver->byId('sagepaydirectpro_cc_owner')->clear(); |
68
|
|
|
$this->webDriver->byId('sagepaydirectpro_cc_owner')->sendKeys( |
69
|
|
|
$this->customer->getBillingFirstName() . ' ' . $this->customer->getBillingLastName() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.