diff --git a/src/Message/RestFetchAgreementRequest.php b/src/Message/RestFetchAgreementRequest.php new file mode 100644 index 0000000..65524c1 --- /dev/null +++ b/src/Message/RestFetchAgreementRequest.php @@ -0,0 +1,75 @@ + + * // Fetch the transaction so that details can be found for refund, etc. + * $transaction = $gateway->fetchAgreement(); + * $transaction->setAgreementId($agreementId); + * $response = $transaction->send(); + * $data = $response->getData(); + * echo "Gateway fetchAgreement response data == " . print_r($data, true) . "\n"; + * + * + * @see RestCreateSubscriptionRequest + * @see Omnipay\PayPal\RestGateway + * @link https://developer.paypal.com/docs/api/payments.billing-agreements#agreement_get + */ +class RestFetchAgreementRequest extends AbstractRestRequest +{ + public function getData() + { + $this->validate('agreementId'); + return array(); + } + + /** + * Get the agreement id + * + * @return mixed + */ + public function getAgreementId() + { + return $this->getParameter('agreementId'); + } + + /** + * Set the agreement id + * + * @param $value + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setAgreementId($value) + { + return $this->setParameter('agreementId', $value); + } + + /** + * Get HTTP Method. + * + * The HTTP method for fetchTransaction requests must be GET. + * Using POST results in an error 500 from PayPal. + * + * @return string + */ + protected function getHttpMethod() + { + return 'GET'; + } + + public function getEndpoint() + { + return parent::getEndpoint() . '/payments/billing-agreement/' . $this->getAgreementId(); + } +} diff --git a/src/RestGateway.php b/src/RestGateway.php index d6ae4f3..dd2da08 100644 --- a/src/RestGateway.php +++ b/src/RestGateway.php @@ -723,6 +723,20 @@ public function searchTransaction(array $parameters = array()) return $this->createRequest('\Omnipay\PayPal\Message\RestSearchTransactionRequest', $parameters); } + /** + * Retrieve an agreement + * + * Use this call to fetch agreement details + * + * @link https://developer.paypal.com/docs/api/payments.billing-agreements#agreement_get + * @param array $parameters + * @return Message\AbstractRestRequest + */ + public function fetchAgreement(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PayPal\Message\RestFetchAgreementRequest', $parameters); + } + /** * @param array $parameters * @@ -744,7 +758,6 @@ public function verifyWebhookSignature(array $parameters = []) } // TODO: Update an agreement - // TODO: Retrieve an agreement // TODO: Set outstanding agreement amounts // TODO: Bill outstanding agreement amounts }