public function testCaptureFailure() { $this->setMockHttpResponse('CIMCaptureFailure.txt'); $response = $this->gateway->capture($this->captureOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Approval Code is required.', $response->getMessage()); }
public function testCaptureFailure() { $this->setMockHttpResponse('AIMCaptureFailure.txt'); $response = $this->gateway->capture($this->captureOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertSame('{"approvalCode":"","transId":"0"}', $response->getTransactionReference()); $this->assertSame('The transaction cannot be found.', $response->getMessage()); }
public function testAuthorizeCapture() { $cardRef = $this->createCard(); // Authorize $params = array('cardReference' => $cardRef, 'amount' => 100.0, 'description' => 'Hello World'); $request = $this->gateway->authorize($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Authorize transaction should get created'); $transRef = $response->getTransactionReference(); $this->assertNotNull($transRef, 'Transaction reference should exist'); // Capture $params = array('transactionReference' => $transRef, 'amount' => 100.0); $request = $this->gateway->capture($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Capture transaction should get created'); $this->assertNotNull($response->getTransactionReference(), 'Transaction reference should exist'); }
public function testIntegration() { // Create card $rand = rand(100000, 999999); $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => "kaylee{$rand}@serenity.com"); $request = $this->gateway->createCard($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Profile should get created'); $this->assertNotNull($response->getCardReference(), 'Card reference should be returned'); $cardRef = $response->getCardReference(); // Try different creating card for same user $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => "kaylee{$rand}@serenity.com"); $params['card']['number'] = '4007000000027'; $request = $this->gateway->createCard($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Should be a success as we create a payment profile'); $this->assertNotNull($response->getCardReference(), 'Card reference should be returned'); // Try creating same card for the same user without force card update flag. $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => "kaylee{$rand}@serenity.com"); $request = $this->gateway->createCard($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertFalse($response->isSuccessful(), 'Should not success as we tried creating duplicate profile'); $this->assertNull($response->getCardReference(), 'Card reference should be returned'); // Try creating same card for the same user again with force card update flag. $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => "kaylee{$rand}@serenity.com", 'forceCardUpdate' => true); $request = $this->gateway->createCard($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Should succeed updating of the existing payment profile'); $this->assertEquals($cardRef, $response->getCardReference(), 'Card reference should be same as with the one newly created'); // Create Authorize only transaction $params = array('cardReference' => $cardRef, 'amount' => 100.0, 'description'); $request = $this->gateway->authorize($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Authorize transaction should get created'); $this->assertNotNull($response->getTransactionReference(), 'Transaction reference should exist'); $transRef = $response->getTransactionReference(); // Capture the authorised transaction $params = array('transactionReference' => $transRef, 'amount' => 100.0); $request = $this->gateway->capture($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Capture transaction should get created'); $this->assertNotNull($response->getTransactionReference(), 'Transaction reference should exist'); $captureTransRef = $response->getTransactionReference(); // Make a purchase using the saved card. i.e auth and capture $params = array('cardReference' => $cardRef, 'amount' => 110.0); $request = $this->gateway->purchase($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Purchase transaction should get created'); $this->assertNotNull($response->getTransactionReference(), 'Transaction reference should exist'); $purchaseTransRef = $response->getTransactionReference(); // Make a refund on the purchase transaction $params = array('transactionReference' => $purchaseTransRef, 'amount' => 110.0); $request = $this->gateway->refund($params); $request->setDeveloperMode(true); $response = $request->send(); // todo: Fix refunds, and add unit tests using mocks // $this->assertTrue($response->isSuccessful(), 'Refund transaction should get created'); // $this->assertNotNull($response->getTransactionReference(), 'Transaction reference should exist'); }