コード例 #1
0
 public static function main()
 {
     $amount = 30.0;
     //Required
     $cardBrand = "visa";
     //Optional
     $maxInstallmentNoInterest = 2;
     //Optional
     try {
         /**
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = new PagSeguroAccountCredentials("*****@*****.**",
          *   "E231B2C9BCC8474DA2E260B6C8CF60D3");
          */
         $credentials = PagSeguroConfig::getAccountCredentials();
         // Application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         $installments = PagSeguroInstallmentService::getInstallments($credentials, $amount, $cardBrand, $maxInstallmentNoInterest);
         self::printInstallment($installments);
     } catch (Exception $e) {
         die($e->getMessage());
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
コード例 #2
0
ファイル: getInstallments.php プロジェクト: songinfo/php
 public static function main()
 {
     try {
         /**
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         // seller authentication
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         $session = "97e12ffaaad04452b9e2b5e9efefd3ee";
         $cardBrand = "visa";
         try {
             $installments = PagSeguroInstallmentService::getInstallments($credentials, $session, "5000.00", $cardBrand);
         } catch (Exception $e) {
             die($e->getMessage());
         }
         self::printInstallment($installments);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
コード例 #3
0
 /**
  * Get from webservice installments for direct payment.
  * @param PagSeguroCredentials $credentials
  * @param $amount
  * @param $cardBrand
  * @param $maxInstallmentNoInterest
  * @return bool|PagSeguroInstallment
  * @throws Exception
  * @throws PagSeguroServiceException
  */
 public static function getInstallments(PagSeguroCredentials $credentials, $amount, $cardBrand = null, $maxInstallmentNoInterest = null)
 {
     $amount = PagSeguroHelper::decimalFormat($amount);
     LogPagSeguro::info("PagSeguroInstallmentService.getInstallments(" . $amount . ") - begin");
     self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get(self::buildInstallmentURL(self::$connectionData, $amount, $cardBrand, $maxInstallmentNoInterest), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse());
                 LogPagSeguro::info("PagSeguroInstallmentService.getInstallments() - end ");
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($installments) ? $installments : false;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }