*/
class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
- use \Civi\Test\GuzzleTestTrait;
-
- /**
- * @var \CRM_Core_Payment_AuthorizeNet
- */
- protected $processor;
+ use CRM_Core_Payment_AuthorizeNetTrait;
public function setUp() {
parent::setUp();
* Test doing a one-off payment.
*
* @throws \Civi\Payment\Exception\PaymentProcessorException
+ * @throws \CiviCRM_API3_Exception
*/
public function testSinglePayment() {
- $this->createMockHandler([$this->getExpectedSinglePaymentResponse()]);
- $this->setUpClientWithHistoryContainer();
- $this->processor->setGuzzleClient($this->getGuzzleClient());
+ $this->setupMockHandler();
$params = $this->getBillingParams();
$params['amount'] = 5.24;
$this->processor->doPayment($params);
$this->assertEquals($this->getExpectedSinglePaymentRequest(), $this->getRequestBodies()[0]);
}
- /**
- * Get the expected response from Authorize.net.
- *
- * @return string
- */
- public function getExpectedSinglePaymentResponse() {
- return '"1","1","1","(TESTMODE) This transaction has been approved.","000000","P","0","","","5.24","CC","auth_capture","","John","O'Connor","","","","","","","","","","","","","","","","","","","","","","","",""';
- }
-
- /**
- * Get the expected request from Authorize.net.
- *
- * @return string
- */
- public function getExpectedSinglePaymentRequest() {
- return 'x_login=4y5BfuW7jm&x_tran_key=4cAmW927n8uLf5J8&x_email_customer=&x_first_name=John&x_last_name=O%27Connor&x_address=&x_city=&x_state=&x_zip=&x_country=&x_customer_ip=&x_email=&x_invoice_num=&x_amount=5.24&x_currency_code=&x_description=&x_cust_id=&x_relay_response=FALSE&x_delim_data=TRUE&x_delim_char=%2C&x_encap_char=%22&x_card_num=4444333322221111&x_card_code=123&x_exp_date=10%2F2022&x_test_request=TRUE';
- }
-
/**
* Create a single post dated payment as a recurring transaction.
*
* Test works but not both due to some form of caching going on in the SmartySingleton
*/
public function testCreateSingleNowDated() {
- $this->createMockHandler([$this->getExpectedResponse()]);
- $this->setUpClientWithHistoryContainer();
- $this->processor->setGuzzleClient($this->getGuzzleClient());
+ $this->isRecur = TRUE;
+ $this->setupMockHandler();
$firstName = 'John';
$lastName = "O\'Connor";
$nameParams = ['first_name' => 'John', 'last_name' => $lastName];
* Create a single post dated payment as a recurring transaction.
*/
public function testCreateSinglePostDated() {
- $this->createMockHandler([$this->getExpectedResponse()]);
- $this->setUpClientWithHistoryContainer();
- $this->processor->setGuzzleClient($this->getGuzzleClient());
+ $this->isRecur = TRUE;
+ $this->setupMockHandler();
$start_date = date('Ymd', strtotime('+ 1 week'));
$firstName = 'John';
);
$response = $this->getResponseBodies();
- $this->assertEquals($this->getExpectedResponse(), $response[0], 3);
+ $this->assertEquals($this->getExpectedRecurResponse(), $response[0], 3);
$requests = $this->getRequestBodies();
$this->assertEquals($this->getExpectedRequest($contactId, date('Y-m-d', strtotime($start_date)), 70.23, 3, 4007000000027, '2022-10'), $requests[0]);
}
';
}
- /**
- * Get a successful response to setting up a recurring.
- *
- * @return string
- */
- public function getExpectedResponse() {
- return '<?xml version="1.0" encoding="utf-8"?><ARBCreateSubscriptionResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><refId>8d468ca1b1dd5c2b56c7</refId><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><subscriptionId>6632052</subscriptionId><profile><customerProfileId>1512023280</customerProfileId><customerPaymentProfileId>1512027350</customerPaymentProfileId></profile></ARBCreateSubscriptionResponse>';
- }
-
/**
* Get some basic billing parameters.
*