Example #1
0
 public static function main()
 {
     // Substitute the code below with a valid pre-approval code for your account
     $preApprovalCode = "E48DD6BD353560C554BFCFB5D536A98C";
     try {
         /**
          * @todo
          * #### Credentials #####
          * Replace the parameters below with your credentials (e-mail and token)
          * You can also get your credentials from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
         $response = PagSeguroPreApprovalService::cancelPreApproval($credentials, $preApprovalCode);
         self::printResponse($response);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 /**
  * @param PagSeguroCredentials $credentials
  * @param $code
  * @return null|PagSeguroParserData
  * @throws Exception
  * @throws PagSeguroServiceException
  */
 public static function cancelPreApproval(PagSeguroCredentials $credentials, $code)
 {
     //Logging
     $log['text'] = "PagSeguroNotificationService.PreApprovalCancel({$code}) - begin";
     LogPagSeguro::info($log['text']);
     self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get(self::buildPreApprovalCancelUrl(self::$connectionData, $code), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset());
         self::$service = "PreApprovalCancel";
         return self::getResult($connection, $code);
     } catch (PagSeguroServiceException $err) {
         //Logging
         LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage());
         //Exception
         throw $err;
     } catch (Exception $err) {
         //Logging
         LogPagSeguro::error("Exception: " . $err->getMessage());
         //Exception
         throw $err;
     }
 }
 public function doPreApproval(PagSeguroCredentials $credentials, $onlyCheckoutCode = false)
 {
     return PagSeguroPreApprovalService::createPreApprovalRequest($credentials, $this);
 }
 /**
  * @param PagSeguroCredentials $credentials
  * @return array|null|PagSeguroParserData
  */
 public function register(PagSeguroCredentials $credentials)
 {
     return PagSeguroPreApprovalService::paymentCharge($credentials, $this);
 }