Exemplo n.º 1
0
 /**
  * REST API method card/process implementation
  * @param string $userId user's identifier
  * @param string $cardToken credit card token (temporary or permanent)
  * @param string $orderId merchant's order ID that will be returned back in a callback
  * @param float $price price in real currency
  * @param string $currency currency code as ISO 4217
  * @param string $description product description
  * @param string $ip user's IP address
  * @param string $acsReturnUrl URL where 3DSecure service will return user after the authentication
  * @param null|bool $remember indicates whether a user wants to remember his credit card in Merchant's service.
  *  If true , then permanenToken ​in response will contain token, that will be used for transaction processing,
  *  instead of temporary token
  * @param null|bool $verifyCard if true, then transaction price will be set to 1 EUR, that will be put on hold and
  *  then instantly returned
  * @param null|bool $recurring indicates whether a user wants to subscribe to recurring payments
  * @param null|int $recurringInterval automatic recurring interval in days (if not set or set to 0, then only manual
  *  recurring will be active)
  * @param null|int $recurringTrial Recurring trial period in days (first recurring payment will occur after trial).
  *  Recurring trial will work only if recurring interval is set
  * @param array $attributes custom attributes data
  * @return Request card/process request instance
  * @throws ErrorException if there is an API error
  */
 public function cardProcess($userId, $cardToken, $orderId, $price, $currency, $description, $ip, $acsReturnUrl, $remember = null, $verifyCard = null, $recurring = null, $recurringInterval = null, $recurringTrial = null, array $attributes = [])
 {
     $parameters = ['user' => (string) $userId, 'card_token' => (string) $cardToken, 'order_id' => (string) $orderId, 'price' => (double) $price, 'currency' => (string) $currency, 'description' => (string) $description, 'ip' => (string) $ip, 'acs_return_url' => (string) $acsReturnUrl];
     if (!is_null($remember)) {
         $parameters['remember'] = (bool) $remember;
     }
     if (!is_null($verifyCard)) {
         $parameters['verify_card'] = (bool) $verifyCard;
     }
     if (!is_null($recurring)) {
         $parameters['recurring'] = (bool) $recurring;
     }
     if (!is_null($recurringInterval)) {
         $parameters['recurring_interval'] = (int) $recurringInterval;
     }
     if (!is_null($recurringTrial)) {
         $parameters['recurring_trial'] = (int) $recurringTrial;
     }
     foreach ($attributes as $attributeName => $attributeValue) {
         $parameters[sprintf('attr_%s', $attributeName)] = $attributeValue;
     }
     return $this->getRequest('card/process', $parameters, function ($string) {
         return ProcessResponse::initializeByString($string);
     });
 }
Exemplo n.º 2
0
    public function testProcessResponse()
    {
        $Response = ProcessResponse::initializeByString('{
"id": 1326123574311498453, "success": true,
"card": {
"lastFour": "4242",
"mask": "************4242",
"type": "visa",
"expirationMonth": "4",
"expirationYear": "2020" },
"acs": {
"url": "https://example.com/ACS", "parameters": {
"MD": "eyJ0cmFuc2Fj...",
"PaReq": "eJxdUWF...",
"TermUrl": "http://example.com/return"
} },
"permanentToken": "9a083895d07ca58f6e5505bd19ed35ca9a083895d07ca58f6e5505bd19ed35ca", "recurring": {
"frequency": 1,
"endsAt": "2015-10-22T11:49:23+03:00" }
}');
        $this->assertEquals('1326123574311498453', $Response->getId());
        $this->assertTrue($Response->isSuccess());
        $this->assertEquals('4242', $Response->getCard()->getLastFour());
        $this->assertEquals('************4242', $Response->getCard()->getMask());
        $this->assertEquals(4, $Response->getCard()->getExpirationMonth());
        $this->assertEquals(2020, $Response->getCard()->getExpirationYear());
        $this->assertEquals('https://example.com/ACS', $Response->getAccessControlServer()->getUrl());
        $this->assertEquals('eyJ0cmFuc2Fj...', $Response->getAccessControlServer()->getParameters()->getMerchantData());
        $this->assertEquals('eJxdUWF...', $Response->getAccessControlServer()->getParameters()->getPaymentAuthorizationRequest());
        $this->assertEquals('http://example.com/return', $Response->getAccessControlServer()->getParameters()->getTermsUrl());
        $this->assertEquals('9a083895d07ca58f6e5505bd19ed35ca9a083895d07ca58f6e5505bd19ed35ca', $Response->getPermanentToken());
        $this->assertEquals(1, $Response->getRecurring()->getFrequency());
        $this->assertEquals(1445503763, $Response->getRecurring()->getEndsAt());
        $this->assertEquals('process result
    id:             1326123574311498453
    success:        true
    permanentToken: 9a083895d07ca58f6e5505bd19ed35ca9a083895d07ca58f6e5505bd19ed35ca
    card
        four:       4242
        mask:       ************4242
        type:       visa
        exp. month: 4
        exp. year:  2020
    acs
        url:       https://example.com/ACS
        parameters
            MD:    eyJ0cmFuc2Fj...
            PaReq: eJxdUWF...
            Terms: http://example.com/return
        query:     MD=eyJ0cmFuc2Fj...&PaReq=eJxdUWF...&TermUrl=http%3A%2F%2Fexample.com%2Freturn
    recurring
        frequency:  1
        endsAt:     2015-10-22T08:49:23+0000', (string) $Response);
    }