Commit | Line | Data |
---|---|---|
0dbefed3 EM |
1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | ||
5 | /** | |
6 | * Class CRM_Core_Payment_PayPalProIPNTest | |
7 | */ | |
8 | class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { | |
9 | protected $_contributionID; | |
10 | protected $_invoiceID = 'c2r9c15f7be20b4f3fef1f77e4c37424'; | |
11 | protected $_financialTypeID = 1; | |
12 | protected $_contactID; | |
13 | protected $_contributionRecurID; | |
14 | protected $_contributionPageID; | |
15 | protected $_paymentProcessorID; | |
16 | ||
00be9182 | 17 | public function setUp() { |
0dbefed3 EM |
18 | parent::setUp(); |
19 | $this->_paymentProcessorID = $this->paymentProcessorCreate(array( | |
20 | 'payment_processor_type_id' => 'AuthNet', | |
21 | )); | |
22 | $this->_contactID = $this->individualCreate(); | |
23 | $contributionPage = $this->callAPISuccess('contribution_page', 'create', array( | |
24 | 'title' => "Test Contribution Page", | |
25 | 'financial_type_id' => $this->_financialTypeID, | |
26 | 'currency' => 'USD', | |
27 | 'payment_processor' => $this->_paymentProcessorID, | |
28 | )); | |
29 | $this->_contributionPageID = $contributionPage['id']; | |
30 | } | |
31 | ||
00be9182 | 32 | public function tearDown() { |
0dbefed3 EM |
33 | $this->quickCleanUpFinancialEntities(); |
34 | } | |
35 | ||
36 | /** | |
100fef9d | 37 | * Test IPN response updates contribution_recur & contribution for first & second contribution |
0dbefed3 | 38 | */ |
00be9182 | 39 | public function testIPNPaymentRecurSuccess() { |
0dbefed3 EM |
40 | $this->setupRecurringPaymentProcessorTransaction(); |
41 | $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); | |
42 | $paypalIPN->main(); | |
43 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); | |
44 | $this->assertEquals(1, $contribution['contribution_status_id']); | |
45 | $this->assertEquals('6511143069', $contribution['trxn_id']); | |
46 | // source gets set by processor | |
47 | $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); | |
48 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); | |
49 | $this->assertEquals(5, $contributionRecur['contribution_status_id']); | |
50 | $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction()); | |
51 | $paypalIPN->main(); | |
92915c55 TO |
52 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
53 | 'contribution_recur_id' => $this->_contributionRecurID, | |
54 | 'sequential' => 1 | |
55 | )); | |
0dbefed3 EM |
56 | $this->assertEquals(2, $contribution['count']); |
57 | $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); | |
58 | } | |
59 | ||
8c15aab2 | 60 | /** |
100fef9d | 61 | * Test IPN response updates contribution_recur & contribution for first & second contribution |
8c15aab2 | 62 | */ |
00be9182 | 63 | public function testIPNPaymentMembershipRecurSuccess() { |
8c15aab2 EM |
64 | $this->setupMembershipRecurringPaymentProcessorTransaction(); |
65 | $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); | |
66 | $paypalIPN->main(); | |
67 | $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); | |
68 | $this->assertEquals(1, $contribution['contribution_status_id']); | |
69 | $this->assertEquals('6511143069', $contribution['trxn_id']); | |
70 | // source gets set by processor | |
71 | $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); | |
72 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); | |
73 | $this->assertEquals(5, $contributionRecur['contribution_status_id']); | |
74 | $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction()); | |
75 | $paypalIPN->main(); | |
92915c55 TO |
76 | $contribution = $this->callAPISuccess('contribution', 'get', array( |
77 | 'contribution_recur_id' => $this->_contributionRecurID, | |
78 | 'sequential' => 1 | |
79 | )); | |
8c15aab2 EM |
80 | $this->assertEquals(2, $contribution['count']); |
81 | $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); | |
6c6e6187 | 82 | $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'])); |
92915c55 TO |
83 | $this->callAPISuccessGetSingle('line_item', array( |
84 | 'contribution_id' => $contribution['values'][1]['id'], | |
85 | 'entity_table' => 'civicrm_membership' | |
86 | )); | |
8c15aab2 EM |
87 | } |
88 | ||
0dbefed3 | 89 | /** |
0dbefed3 | 90 | */ |
00be9182 | 91 | public function getRecurTransaction() { |
0dbefed3 EM |
92 | return array( |
93 | "x_amount" => "200.00", | |
94 | "x_country" => 'US', | |
95 | "x_phone" => "", | |
96 | "x_fax" => "", | |
97 | "x_email" => "me@gmail.com", | |
98 | "x_description" => "lots of money", | |
99 | "x_type" => "auth_capture", | |
100 | "x_ship_to_first_name" => "", | |
101 | "x_ship_to_last_name" => "", | |
102 | "x_ship_to_company" => "", | |
103 | "x_ship_to_address" => "", | |
104 | "x_ship_to_city" => "", | |
105 | "x_ship_to_state" => "", | |
106 | "x_ship_to_zip" => "", | |
107 | "x_ship_to_country" => "", | |
108 | "x_tax" => "0.00", | |
109 | "x_duty" => "0.00", | |
110 | "x_freight" => "0.00", | |
111 | "x_tax_exempt" => "FALSE", | |
112 | "x_po_num" => "", | |
113 | "x_MD5_Hash" => "1B7C0C5B4DEDD9CAD0636E35E22FC594", | |
114 | "x_cvv2_resp_code" => "", | |
115 | "x_cavv_response" => "", | |
116 | "x_test_request" => "false", | |
117 | "x_subscription_id" => $this->_contributionRecurID, | |
118 | "x_subscription_paynum" => "1", | |
119 | 'x_first_name' => 'Robert', | |
120 | 'x_zip' => '90210', | |
121 | 'x_state' => 'WA', | |
122 | 'x_city' => 'Dallas', | |
123 | 'x_address' => '41 My ST', | |
124 | 'x_invoice_num' => $this->_contributionID, | |
125 | 'x_cust_id' => $this->_contactID, | |
126 | 'x_company' => 'nowhere@civicrm.org', | |
127 | 'x_last_name' => 'Roberts', | |
128 | 'x_account_number' => 'XXXX5077', | |
129 | 'x_card_type' => 'Visa', | |
130 | 'x_method' => 'CC', | |
131 | 'x_trans_id' => '6511143069', | |
132 | 'x_auth_code' => '123456', | |
133 | 'x_avs_code' => 'Z', | |
134 | 'x_response_reason_text' => 'This transaction has been approved.', | |
135 | 'x_response_reason_code' => '1', | |
21dfd5f5 | 136 | 'x_response_code' => '1', |
0dbefed3 EM |
137 | ); |
138 | } | |
139 | ||
140 | /** | |
141 | * @return array | |
142 | */ | |
00be9182 | 143 | public function getRecurSubsequentTransaction() { |
0dbefed3 EM |
144 | return array_merge($this->getRecurTransaction(), array( |
145 | 'x_trans_id' => 'second_one', | |
146 | 'x_MD5_Hash' => 'EA7A3CD65A85757827F51212CA1486A8', | |
147 | )); | |
148 | } | |
149 | } |