Ejemplo n.º 1
0
 public function provideAliasResponse($createAlias = true, $noValidCardnumber = false)
 {
     /*
      *  Create an alias request to PostFinance
      */
     $passphrase = new Passphrase(PASSPHRASE_SHA_IN);
     $shaComposer = new AllParametersShaComposer($passphrase);
     $createAliasRequest = new CreateAliasRequest($shaComposer);
     $createAliasRequest->setPspid(PSPID);
     $createAliasRequest->setAccepturl('http://www.example.com');
     $createAliasRequest->setExceptionurl('http://www.example.com');
     if ($createAlias == true) {
         $unique_alias = uniqid('customer_');
         // create a unique alias
         $alias = new Alias($unique_alias);
         $createAliasRequest->setAlias($alias);
     }
     $createAliasRequest->validate();
     $body = array();
     foreach ($createAliasRequest->toArray() as $key => $value) {
         $body[strtoupper($key)] = $value;
     }
     $body['SHASIGN'] = $createAliasRequest->getShaSign();
     $body['CN'] = 'Don Corleone';
     $body['CARDNO'] = $noValidCardnumber ? '' : '4111111111111111';
     // PostFinance Visa test cardnumber
     $body['CVC'] = '777';
     $body['ED'] = date('my', strtotime('+1 year'));
     // test-date should be in the future
     $client = new Client($createAliasRequest->getPostFinanceUri());
     $request = $client->post(null, null, $body);
     $response = $request->send();
     $url = parse_url($response->getInfo('url'));
     $params = array();
     parse_str($url['query'], $params);
     /*
      * Validate alias response from PostFinance
      */
     $createAliasResponse = new CreateAliasResponse($params);
     return $createAliasResponse;
 }
 /**
  * @test
  * @expectedException \RuntimeException
  */
 public function IsInvalidWhenFieldsAreMissing()
 {
     $aliasRequest = new CreateAliasRequest(new FakeShaComposer());
     $aliasRequest->validate();
 }