67a10cc4 |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | Copyright CiviCRM LLC. All rights reserved. | |
5 | | | |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | |
8 | | and copyright information, see https://civicrm.org/licensing | |
9 | +--------------------------------------------------------------------+ |
10 | */ |
11 | |
12 | /** |
13 | * Class CRM_Core_Payment_PaypalPro |
14 | * @group headless |
15 | */ |
16 | class CRM_Core_Payment_PaypalStdTest extends CiviUnitTestCase { |
17 | |
18 | /** |
19 | * @var \CRM_Core_Payment_PayPalImpl |
20 | */ |
21 | protected $processor; |
22 | |
23 | /** |
24 | * @throws \CiviCRM_API3_Exception |
25 | */ |
26 | public function setUp() { |
27 | parent::setUp(); |
28 | $processorID = $this->processorCreate([ |
29 | 'payment_processor_type_id' => 'PayPal_Standard', |
30 | 'is_recur' => TRUE, |
31 | 'billing_mode' => 4, |
32 | 'url_site' => 'https://www.paypal.com/', |
33 | 'url_recur' => 'https://www.paypal.com/', |
34 | 'class_name' => 'Payment_PayPalImpl', |
35 | ]); |
36 | |
37 | $this->processor = Civi\Payment\System::singleton()->getById($processorID); |
38 | } |
39 | |
40 | /** |
41 | * @throws \CRM_Core_Exception |
42 | */ |
594a9328 |
43 | public function tearDown(): void { |
67a10cc4 |
44 | $this->quickCleanUpFinancialEntities(); |
45 | parent::tearDown(); |
46 | } |
47 | |
48 | /** |
49 | * Test doing a one-off payment. |
50 | * |
51 | * @throws \Civi\Payment\Exception\PaymentProcessorException |
52 | */ |
53 | public function testSinglePayment() { |
54 | $params = []; |
55 | $params['amount'] = 5.24; |
56 | $params['currency'] = 'USD'; |
57 | $params['invoiceID'] = 'xyz'; |
58 | $params['ip_address'] = '127.0.0.1'; |
59 | $params['qfKey'] = 'w'; |
60 | $params['currencyID'] = 'USD'; |
61 | try { |
62 | $this->processor->doPayment($params); |
63 | } |
64 | catch (CRM_Core_Exception_PrematureExitException $e) { |
65 | $redirectValues = parse_url($e->errorData['url']); |
66 | $this->assertEquals('https', $redirectValues['scheme']); |
67 | $this->assertEquals('www.paypal.com', $redirectValues['host']); |
68 | $this->assertEquals('/cgi-bin/webscr', $redirectValues['path']); |
69 | $query = []; |
70 | parse_str($redirectValues['query'], $query); |
71 | $this->assertEquals(5.24, $query['amount']); |
72 | $this->assertEquals('CiviCRM_SP', $query['bn']); |
73 | } |
74 | } |
75 | |
76 | } |