Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for fetching agreement #235

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/Message/RestFetchAgreementRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* PayPal REST Fetch Transaction Request
*/

namespace Omnipay\PayPal\Message;

/**
* PayPal REST Fetch Agreement Request
*
* To get details of Agreement created by a create subscription request, PayPal provides the /billing-agreements
*
* Example -- note this example assumes that the subscription creation request has been successful
* and that there is already an agreement recorded in Paypal
*
* <code>
* // 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";
* </code>
*
* @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();
}
}
15 changes: 14 additions & 1 deletion src/RestGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
}