15912a4d |
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 | |
b8a960ed |
12 | use Civi\Test\GuzzleTestTrait; |
13 | |
15912a4d |
14 | /** |
15 | * Class CRM_Core_Payment_AuthorizeNetTest |
16 | * @group headless |
17 | */ |
18 | trait CRM_Core_Payment_PaypalProTrait { |
b8a960ed |
19 | use GuzzleTestTrait; |
15912a4d |
20 | |
21 | /** |
22 | * @var \CRM_Core_Payment_PayPalImpl |
23 | */ |
24 | protected $processor; |
25 | |
26 | /** |
27 | * Is this a recurring transaction. |
28 | * |
29 | * @var bool |
30 | */ |
31 | protected $isRecur = FALSE; |
32 | |
33 | /** |
34 | * Get the expected response from Paypal Pro for a single payment. |
35 | * |
36 | * @return array |
37 | */ |
38 | public function getExpectedSinglePaymentResponses() { |
39 | return [ |
b8a960ed |
40 | 'TIMESTAMP=2020%2d09%2d04T04%3a05%3a11Z&CORRELATIONID=246132f75a6f3&ACK=Success&VERSION=3&BUILD=54790461&AMT=5%2e24&CURRENCYCODE=USD&AVSCODE=A&CVV2MATCH=M&TRANSACTIONID=9TU23130NB247535M', |
41 | 'RECEIVERBUSINESS=sunil%2e_1183377782_biz%40webaccess%2eco%2ein&RECEIVEREMAIL=sunil%2e_1183377782_biz%40webaccess%2eco%2ein&RECEIVERID=BNCETES6EECQQ&EMAIL=86Y37281N5671683A%40dcc2%2epaypal%2ecom&PAYERID=RYUKTRK2TRA4J&PAYERSTATUS=verified&COUNTRYCODE=US&ADDRESSOWNER=PayPal&ADDRESSSTATUS=None&INVNUM=68023&SALESTAX=0%2e00&TIMESTAMP=2020%2d09%2d04T05%3a18%3a33Z&CORRELATIONID=b74cfc6e440ea&ACK=Success&VERSION=3&BUILD=54686869&FIRSTNAME=John&LASTNAME=O%27Connor&TRANSACTIONID=58E89379MT3066727&RECEIPTID=3065%2d9946%2d9883%2d0395&TRANSACTIONTYPE=webaccept&PAYMENTTYPE=instant&ORDERTIME=2020%2d09%2d04T05%3a18%3a28Z&AMT=5%2e24&FEEAMT=0%2e45&TAXAMT=0%2e00&CURRENCYCODE=USD&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None&SHIPPINGMETHOD=Default&L_QTY0=1&L_TAXAMT0=0%2e00&L_CURRENCYCODE0=USD&L_AMT0=5%2e24', |
15912a4d |
42 | ]; |
43 | } |
44 | |
45 | /** |
46 | * Get the expected request from Authorize.net. |
47 | * |
48 | * @return array |
49 | */ |
50 | public function getExpectedSinglePaymentRequests() { |
51 | return [ |
b8a960ed |
52 | 'user=sunil._1183377782_biz_api1.webaccess.co.in&pwd=1183377788&version=3&signature=APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH&subject=&method=DoDirectPayment&paymentAction=Sale&amt=5.24¤cyCode=USD&invnum=xyz&ipaddress=127.0.0.1&creditCardType=Visa&acct=4444333322221111&expDate=102022&cvv2=123&firstName=John&lastName=O%27Connor&email=&street=8+Hobbitton+Road&city=The+Shire&state=IL&countryCode=US&zip=5010&desc=&custom=&BUTTONSOURCE=CiviCRM_SP', |
53 | 'TRANSACTIONID=9TU23130NB247535M&user=sunil._1183377782_biz_api1.webaccess.co.in&pwd=1183377788&version=3&signature=APixCoQ-Zsaj-u3IH7mD5Do-7HUqA9loGnLSzsZga9Zr-aNmaJa3WGPH&subject=&method=GetTransactionDetails', |
15912a4d |
54 | ]; |
55 | } |
56 | |
57 | /** |
58 | * Get the expected request from Authorize.net. |
59 | * |
60 | * @return array |
61 | */ |
62 | public function getExpectedRecurResponses() { |
63 | return [ |
64 | 'placeholder', |
65 | ]; |
66 | } |
67 | |
68 | /** |
69 | * Add a mock handler to the paypal Pro processor for testing. |
70 | * |
71 | * @param int|null $id |
72 | * |
73 | * @throws \CiviCRM_API3_Exception |
74 | */ |
75 | protected function setupMockHandler($id = NULL) { |
76 | if ($id) { |
77 | $this->processor = Civi\Payment\System::singleton()->getById($id); |
78 | } |
79 | $responses = $this->isRecur ? $this->getExpectedRecurResponses() : $this->getExpectedSinglePaymentResponses(); |
80 | // Comment the next line out when trying to capture the response. |
81 | // see https://github.com/civicrm/civicrm-core/pull/18350 |
b8a960ed |
82 | $this->createMockHandler($responses); |
15912a4d |
83 | $this->setUpClientWithHistoryContainer(); |
84 | $this->processor->setGuzzleClient($this->getGuzzleClient()); |
85 | } |
86 | |
87 | /** |
88 | * Create an AuthorizeNet processors with a configured mock handler. |
89 | * |
90 | * @throws \CiviCRM_API3_Exception |
91 | */ |
92 | protected function createPaypalProProcessor() { |
93 | $processorID = $this->paymentProcessorCreate(['is_test' => 0]); |
94 | $this->setupMockHandler($processorID); |
95 | $this->ids['PaymentProcessor']['paypal_pro'] = $processorID; |
96 | } |
97 | |
98 | } |