/**
  * @see RequestEntity::toArray()
  * @dataProvider providerTransactionMockData
  */
 public function testToArray($type, $paymentMethod, $paymentCountry, $ipAddress, $cookie, $userAgent, $expiration)
 {
     $transaction = $this->object->getTransaction();
     $transaction->setType($type)->setPaymentMethod($paymentMethod)->setPaymentCountry($paymentCountry)->setIpAddress($ipAddress)->setCookie($cookie)->setUserAgent($userAgent)->setExpiration($expiration);
     $this->object->setTransaction($transaction);
     $rs = $this->object->toArray();
     $this->assertInternalType('array', $rs);
     $this->assertEquals(1, count($rs));
     $this->assertArrayHasKey('transaction', $rs);
     $transaction = $rs['transaction'];
     $this->assertInternalType('array', $transaction);
     $this->assertEquals(11, count($transaction));
     $this->assertArrayHasKey('expiration', $transaction);
     $this->assertEquals($expiration, $transaction['expiration']);
     $this->assertArrayHasKey('type', $transaction);
     $this->assertEquals($type, $transaction['type']);
     $this->assertArrayHasKey('paymentMethod', $transaction);
     $this->assertEquals($paymentMethod, $transaction['paymentMethod']);
     $this->assertArrayHasKey('paymentCountry', $transaction);
     $this->assertEquals($paymentCountry, $transaction['paymentCountry']);
     $this->assertArrayHasKey('ipAddress', $transaction);
     $this->assertEquals($ipAddress, $transaction['ipAddress']);
     $this->assertArrayHasKey('cookie', $transaction);
     $this->assertEquals($cookie, $transaction['cookie']);
     $this->assertArrayHasKey('userAgent', $transaction);
     $this->assertEquals($userAgent, $transaction['userAgent']);
     $this->assertArrayHasKey('order', $transaction);
     $this->assertInternalType('array', $transaction['order']);
     $this->assertArrayHasKey('creditCard', $transaction);
     $this->assertInternalType('array', $transaction['creditCard']);
     $this->assertArrayHasKey('payer', $transaction);
     $this->assertInternalType('array', $transaction['payer']);
     $this->assertArrayHasKey('extraParameters', $transaction);
     $this->assertInternalType('array', $transaction['extraParameters']);
 }
Example #2
0
 /**
  * Make a request "authorize", "authorizeAndCapture" and "cashCollection" methods.
  *
  * @param  TransactionEntity $transaction
  * @return stdClass
  */
 private function authorizeRequest(TransactionEntity $transaction)
 {
     $requestEntity = new RequestEntity();
     $request = $requestEntity->setCommand('SUBMIT_TRANSACTION')->setMerchant($this->credentials)->setTransaction($transaction)->setIsTest($this->isStaging);
     $this->xmlRequest->addChild('language', $request->getLanguage());
     $this->xmlRequest->addChild('command', $request->getCommand());
     if (!isset($this->xmlRequest->isTest)) {
         $this->xmlRequest->addChild('isTest', $request->getIsTest() ? 'true' : 'false');
     }
     $merchant = $this->xmlRequest->addChild('merchant');
     $merchant->addChild('apiLogin', $request->getMerchant()->getApiLogin());
     $merchant->addChild('apiKey', $request->getMerchant()->getApiKey());
     $xmlTransaction = $this->xmlRequest->addChild('transaction');
     $xmlTransaction->addChild('type', $transaction->getType());
     $xmlTransaction->addChild('paymentMethod', $transaction->getPaymentMethod());
     $xmlTransaction->addChild('paymentCountry', $transaction->getPaymentCountry());
     $xmlTransaction->addChild('ipAddress', $transaction->getIpAddress());
     $xmlTransaction->addChild('cookie', $transaction->getCookie());
     $xmlTransaction->addChild('userAgent', $transaction->getUserAgent());
     $xmlTransaction->addChild('deviceSessionId', $transaction->getDeviceSessionId());
     $expiration = $transaction->getExpiration();
     if ($expiration > 0) {
         $date = new \DateTime('now');
         $date->modify(sprintf('+%d day', $expiration));
         $expirationDate = $date->format('Y-m-d') . 'T' . $date->format('h:i:s');
         $xmlTransaction->addChild('expirationDate', $expirationDate);
     }
     $creditCard = $transaction->getCreditCard();
     if (!$creditCard->isEmpty()) {
         $xmlCreditCard = $xmlTransaction->addChild('creditCard');
         $xmlCreditCard->addChild('number', $creditCard->getNumber());
         $xmlCreditCard->addChild('securityCode', $creditCard->getSecurityCode());
         $xmlCreditCard->addChild('expirationDate', $creditCard->getExpirationDate());
         $xmlCreditCard->addChild('name', $creditCard->getName());
     }
     $payer = $transaction->getPayer();
     if (!$payer->isEmpty()) {
         $xmlPayer = $xmlTransaction->addChild('payer');
         $xmlPayer->addChild('fullName', $payer->getFullName());
         $xmlPayer->addChild('emailAddress', $payer->getEmailAddress());
         $xmlPayer->addChild('contactPhone', $payer->getContactPhone());
         $xmlPayer->addChild('dniNumber', $payer->getDniNumber());
         $billingAddress = $payer->getBillingAddress();
         $xmlBillingAddress = $xmlPayer->addChild('billingAddress');
         $xmlBillingAddress->addChild('street1', $billingAddress->getStreet1());
         $xmlBillingAddress->addChild('street2', $billingAddress->getStreet2());
         $xmlBillingAddress->addChild('city', $billingAddress->getCity());
         $xmlBillingAddress->addChild('state', $billingAddress->getState());
         $xmlBillingAddress->addChild('country', $billingAddress->getCountry());
         $xmlBillingAddress->addChild('postalCode', $billingAddress->getPostalCode());
         $xmlBillingAddress->addChild('phone', $billingAddress->getPhone());
     }
     $order = $transaction->getOrder();
     if (!$order->isEmpty()) {
         $xmlOrder = $xmlTransaction->addChild('order');
         $xmlOrder->addChild('accountId', $request->getMerchant()->getAccountId());
         $xmlOrder->addChild('referenceCode', $order->getReferenceCode());
         $xmlOrder->addChild('description', $order->getDescription());
         $xmlOrder->addChild('language', $order->getLanguage());
         $xmlOrder->addChild('notifyUrl', $order->getNotifyUrl());
     }
     //Order signature.
     $additionalValues = $order->getAdditionalValues()->toArray();
     $tx_value = $additionalValues[0]['additionalValue']['value'];
     $currency = $additionalValues[0]['additionalValue']['currency'];
     $signature = $this->computeSignature($order->getReferenceCode(), $tx_value, $currency);
     $xmlOrder->addChild('signature', $signature);
     //Order signature.
     $buyer = $order->getBuyer();
     if (!$buyer->isEmpty()) {
         $xmlBuyer = $xmlOrder->addChild('buyer');
         $xmlBuyer->addChild('fullName', $buyer->getFullName());
         $xmlBuyer->addChild('emailAddress', $buyer->getEmailAddress());
     }
     if (!is_null($buyer->getDniNumber())) {
         $xmlBuyer->addChild('dniNumber', $buyer->getDniNumber());
     }
     if (!is_null($buyer->getCnpj())) {
         $xmlBuyer->addChild('cnpj', $buyer->getCnpj());
     }
     $shippingAddress = $order->getShippingAddress();
     if (!$shippingAddress->isEmpty()) {
         $xmlShippingAddress = $xmlOrder->addChild('shippingAddress');
         $xmlShippingAddress->addChild('street1', $shippingAddress->getStreet1());
         $xmlShippingAddress->addChild('street2', $shippingAddress->getStreet2());
         $xmlShippingAddress->addChild('city', $shippingAddress->getCity());
         $xmlShippingAddress->addChild('state', $shippingAddress->getState());
         $xmlShippingAddress->addChild('country', $shippingAddress->getCountry());
         $xmlShippingAddress->addChild('postalCode', $shippingAddress->getPostalCode());
         $xmlShippingAddress->addChild('phone', $shippingAddress->getPhone());
         $xmlBuyerShippingAddress = $xmlBuyer->addChild('shippingAddress');
         $xmlBuyerShippingAddress->addChild('street1', $shippingAddress->getStreet1());
         $xmlBuyerShippingAddress->addChild('street2', $shippingAddress->getStreet2());
         $xmlBuyerShippingAddress->addChild('city', $shippingAddress->getCity());
         $xmlBuyerShippingAddress->addChild('state', $shippingAddress->getState());
         $xmlBuyerShippingAddress->addChild('country', $shippingAddress->getCountry());
         $xmlBuyerShippingAddress->addChild('postalCode', $shippingAddress->getPostalCode());
         $xmlBuyerShippingAddress->addChild('phone', $shippingAddress->getPhone());
     }
     $additionalValues = $order->getAdditionalValues()->toArray();
     $xmlAdditionalValues = $xmlOrder->addChild('additionalValues');
     foreach ($additionalValues as $value) {
         $entry = $xmlAdditionalValues->addChild('entry');
         $entry->addChild('string', $value['string']);
         $additionalValue = $entry->addChild('additionalValue');
         $additionalValue->addChild('currency', $value['additionalValue']['currency']);
         $additionalValue->addChild('value', $value['additionalValue']['value']);
     }
     $extraParameters = $transaction->getExtraParameters()->toArray();
     $xmlExtraParameters = $xmlTransaction->addChild('extraParameters');
     if (count($extraParameters) > 0) {
         foreach ($extraParameters as $label => $value) {
             $entry = $xmlExtraParameters->addChild('entry');
             $entry->addChild('string', $label);
             $entry->addChild('string', $value);
         }
     }
     $this->setLastXmlRequest($this->xmlRequest);
     $response = $this->curlRequestXml($this->xmlRequest->asXML());
     $this->resetRequest();
     return $response;
 }