コード例 #1
0
 public function testCustomerAndPaymentProfile()
 {
     // Create a customer profile with the specified email (email is the identifier)
     $email = uniqid('', true) . '@example.com';
     $cardRef = $this->createCard(array('email' => $email));
     // Create a new card in an existing customer profile
     $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => $email);
     $params['card']['number'] = '4007000000027';
     $request = $this->gateway->createCard($params);
     $request->setDeveloperMode(true);
     $response = $request->send();
     $this->assertTrue($response->isSuccessful(), 'Should be successful as we have created a payment profile');
     $this->assertNotNull($response->getCardReference(), 'Card reference should be returned');
     // Create a card with same number in an existing customer profile (should fail)
     $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => $email);
     $request = $this->gateway->createCard($params);
     $request->setDeveloperMode(true);
     $response = $request->send();
     $this->assertFalse($response->isSuccessful(), 'Should fail as we tried creating a duplicate profile');
     $this->assertNull($response->getCardReference(), 'Card reference should be returned');
     // Create a card with the same number in an existing customer profile with auto-update enabled
     $params = array('card' => $this->getValidCard(), 'name' => 'Kaywinnet Lee Frye', 'email' => $email, 'forceCardUpdate' => true);
     $request = $this->gateway->createCard($params);
     $request->setDeveloperMode(true);
     $response = $request->send();
     $this->assertTrue($response->isSuccessful(), 'Should succeed in updating the existing payment profile');
     $this->assertEquals($cardRef, $response->getCardReference(), 'Card reference should be same as with the one newly created');
 }
コード例 #2
0
 public function testCreateCardFailure()
 {
     $this->setMockHttpResponse('CIMCreateCardFailure.txt');
     $response = $this->gateway->createCard($this->createCardOptions)->send();
     $this->assertFalse($response->isSuccessful());
     $this->assertNull($response->getCardReference());
     $this->assertSame('One or more fields in the profile must contain a value.', $response->getMessage());
 }
コード例 #3
0
 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');
 }