This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/_sakura/vendor/paypal/rest-api-sdk-php/sample/billing/SearchBillingTransactions.php

33 lines
1.4 KiB
PHP
Raw Normal View History

2015-06-21 03:30:38 +00:00
<?php
// # Search Billing Transactions Sample
//
// This sample code demonstrate how you can search all billing transactions, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#search-for-transactions
// API used: GET /v1/payments/billing-agreements/<Agreement-Id>/transactions? start-date=yyyy-mm-dd&end-date=yyyy-mm-dd
// Retrieving the Agreement object from Get Billing Agreement. This may not be necessary if you are trying to search for transactions of already created Agreement.
/** @var Agreement $agreement */
$agreement = require 'GetBillingAgreement.php';
// Replace this with your AgreementId to search transactions based on your agreement.
$agreementId = $agreement->getId();
use PayPal\Api\Agreement;
// Adding Params to search transaction within a given time frame.
$params = array('start_date' => date('Y-m-d', strtotime('-15 years')), 'end_date' => date('Y-m-d', strtotime('+5 days')));
try {
$result = Agreement::searchTransactions($agreementId, $params, $apiContext);
} catch (Exception $ex) {
2015-07-01 00:16:22 +00:00
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Search for Transactions", "AgreementTransaction", $agreementId, null, $ex);
2015-06-21 03:30:38 +00:00
exit(1);
}
2015-07-01 00:16:22 +00:00
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Search for Transactions", "AgreementTransaction", $agreementId, $params, $result);
2015-06-21 03:30:38 +00:00
return $agreement;