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