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

Add Fetch Plan & Verify Webhook Requests #212

Open
wants to merge 3 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
74 changes: 74 additions & 0 deletions src/Message/RestFetchPlanRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* PayPal REST Fetch Plan Detail Request
*/

namespace Omnipay\PayPal\Message;

/**
* PayPal REST Fetch Plan Request
*
* To get details about PayPal plans
*
* Example
*
* <code>
* // Fetch PayPal Plan
* $transaction = $this->gateway->fetchPlan([
* 'planId' => 'P-000000000000000000000000',
* ]);
* $response = $transaction->send();
* $data = $response->getData();
* echo "Gateway getPlan response data == " . print_r($data, true) . "\n";
* </code>
*
* @link https://developer.paypal.com/docs/api/payments.billing-plans/#billing-plans_get
*/

class RestFetchPlanRequest extends AbstractRestRequest
{
/**
*
* Get the plan ID
*
* @return string
*/
public function getPlanId()
{
return $this->getParameter('planId');
}

/**
* Set the plan ID
*
* @param string $value
* @return RestFetchPlanRequest provides a fluent interface.
*/
public function setPlanId($value)
{
return $this->setParameter('planId', $value);
}

public function getData()
{
$this->validate('planId');
return array();
}

/**
* Get HTTP Method.
*
* The HTTP method for list plans requests must be GET.
*
* @return string
*/
protected function getHttpMethod()
{
return 'GET';
}

public function getEndpoint()
{
return parent::getEndpoint() . '/payments/billing-plans/' . $this->getPlanId();
}
}
116 changes: 116 additions & 0 deletions src/Message/RestVerifyWebhookRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* PayPal REST Verify Webhook Request
*/

namespace Omnipay\PayPal\Message;

/**
* PayPal REST Verify Webhook Request
*
* Verify a webhook signature
*
* @link https://developer.paypal.com/docs/api/webhooks/#verify-webhook-signature
*/
class RestVerifyWebhookRequest extends AbstractRestRequest
{
public function getAuthAlgo()
{
return $this->getParameter('authAlgo');
}

public function setAuthAlgo($value)
{
$this->setParameter('authAlgo', $value);
}

public function getCertUrl()
{
return $this->getParameter('certUrl');
}

public function setCertUrl($value)
{
$this->setParameter('certUrl', $value);
}

public function getTransmissionId()
{
return $this->getParameter('transmissionId');
}

public function setTransmissionId($value)
{
$this->setParameter('transmissionId', $value);
}

public function getTransmissionSig()
{
return $this->getParameter('transmissionSig');
}

public function setTransmissionSig($value)
{
$this->setParameter('transmissionSig', $value);
}

public function getTransmissionTime()
{
return $this->getParameter('transmissionTime');
}

public function setTransmissionTime($value)
{
$this->setParameter('transmissionTime', $value);
}

public function getWebhookId()
{
return $this->getParameter('webhookId');
}

public function setWebhookId($value)
{
$this->setParameter('webhookId', $value);
}

public function getWebhookEvent()
{
return $this->getParameter('webhookEvent');
}

public function setWebhookEvent(array $value)
{
$this->setParameter('webhookEvent', $value);
}

protected function getEndpoint()
{
return parent::getEndpoint() . '/notifications/verify-webhook-signature';
}

public function getData()
{
$this->validate(
'authAlgo',
'certUrl',
'transmissionId',
'transmissionSig',
'transmissionTime',
'webhookId',
'webhookEvent'
);

$data = array(
'auth_algo' => $this->getAuthAlgo(),
'cert_url' => $this->getCertUrl(),
'transmission_id' => $this->getTransmissionId(),
'transmission_sig' => $this->getTransmissionSig(),
'transmission_time' => $this->getTransmissionTime(),
'webhook_id' => $this->getWebhookId(),
'webhook_event' => $this->getWebhookEvent()
);

return $data;
}
}
29 changes: 27 additions & 2 deletions src/RestGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,19 @@ public function updatePlan(array $parameters = array())
return $this->createRequest('\Omnipay\PayPal\Message\RestUpdatePlanRequest', $parameters);
}

// TODO: Retrieve a plan

/**
* Fetch a billing plan.
*
* Use this call to get details about a billing plan.
*
* @link https://developer.paypal.com/docs/api/payments.billing-plans/#billing-plans_get
* @param array $parameters
* @return \Omnipay\PayPal\Message\RestFetchPlanRequest
*/
public function fetchPlan(array $parameters = array())
{
return $this->createRequest('\Omnipay\PayPal\Message\RestFetchPlanRequest', $parameters);
}

/**
* List billing plans.
Expand Down Expand Up @@ -710,6 +721,20 @@ public function searchTransaction(array $parameters = array())
return $this->createRequest('\Omnipay\PayPal\Message\RestSearchTransactionRequest', $parameters);
}

/**
* Verify a webhook signature
*
* Use this call to verify a webhook signature.
*
* @link https://developer.paypal.com/docs/api/webhooks/#verify-webhook-signature
* @param array $parameters
* @return \Omnipay\PayPal\Message\RestVerifyWebhookRequest
*/
public function verifyWebhook(array $parameters = array())
{
return $this->createRequest('\Omnipay\PayPal\Message\RestVerifyWebhookRequest', $parameters);
}

// TODO: Update an agreement
// TODO: Retrieve an agreement
// TODO: Set outstanding agreement amounts
Expand Down