public static function main() { $preApprovalCharge = new PagSeguroPreApprovalCharge(); $preApprovalCharge->setReference("REF123-1"); $preApprovalCharge->setPreApprovalCode('230B933B11116E66645FFF8DEAB6CF11'); $preApprovalCharge->addItem('0001', 'Parcela 1 do Seguro para Notebook', 1, 100.0); 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"); // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer. $response = $preApprovalCharge->register($credentials); self::printResponse($response); } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }
/** * @param PagSeguroCredentials $credentials * @param PagSeguroPreApprovalCharge $charge * @return null|PagSeguroParserData * @throws Exception * @throws PagSeguroServiceException */ public static function paymentCharge(PagSeguroCredentials $credentials, PagSeguroPreApprovalCharge $charge) { LogPagSeguro::info("PagSeguroPreApprovalService.PreApprovalPaymentCharge(" . $charge->toString() . ") - begin"); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $data = array_merge(self::$connectionData->getCredentials()->getAttributesMap(), PagSeguroPreApprovalParser::getCharge($charge)); try { $connection = new PagSeguroHttpConnection(); $connection->post(self::buildPreApprovalPaymentUrl(self::$connectionData), $data, self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); self::$service = "PreApprovalPaymentCharge"; return self::getResult($connection); } catch (PagSeguroServiceException $err) { //Logging LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage()); //Exception throw $err; } catch (Exception $err) { //Logging LogPagSeguro::error("Exception: " . $err->getMessage()); //Exception throw $err; } }