From 734349964092f2acfb6139909e039d2648a5736e Mon Sep 17 00:00:00 2001 From: Angelo Date: Wed, 19 Sep 2018 12:27:22 +0200 Subject: [PATCH 1/3] Add Fetch Plan Request Ability to fetch plan details --- src/Message/RestFetchPlanRequest.php | 74 ++++++++++++++++++++++++++++ src/RestGateway.php | 15 +++++- 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100755 src/Message/RestFetchPlanRequest.php diff --git a/src/Message/RestFetchPlanRequest.php b/src/Message/RestFetchPlanRequest.php new file mode 100755 index 0000000..07cb7ad --- /dev/null +++ b/src/Message/RestFetchPlanRequest.php @@ -0,0 +1,74 @@ + + * // 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"; + * + * + * @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(); + } +} diff --git a/src/RestGateway.php b/src/RestGateway.php index 7013053..ef624b7 100644 --- a/src/RestGateway.php +++ b/src/RestGateway.php @@ -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. From d973984ba9b76a1eca154ef6f4c9dbea0fae3df5 Mon Sep 17 00:00:00 2001 From: Angelo Date: Thu, 27 Sep 2018 18:34:17 +0200 Subject: [PATCH 2/3] Verify Webhook Signature Request --- src/Message/RestVerifyWebhookRequest.php | 107 +++++++++++++++++++++++ src/RestGateway.php | 14 +++ 2 files changed, 121 insertions(+) create mode 100644 src/Message/RestVerifyWebhookRequest.php diff --git a/src/Message/RestVerifyWebhookRequest.php b/src/Message/RestVerifyWebhookRequest.php new file mode 100644 index 0000000..a915ae9 --- /dev/null +++ b/src/Message/RestVerifyWebhookRequest.php @@ -0,0 +1,107 @@ +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; + } +} diff --git a/src/RestGateway.php b/src/RestGateway.php index ef624b7..b74f234 100644 --- a/src/RestGateway.php +++ b/src/RestGateway.php @@ -721,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 From b59cc9fac9aa8d75cfafd50b913bf235dbaab628 Mon Sep 17 00:00:00 2001 From: Angelo Date: Thu, 27 Sep 2018 18:38:47 +0200 Subject: [PATCH 3/3] Travis CI fix --- src/Message/RestVerifyWebhookRequest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Message/RestVerifyWebhookRequest.php b/src/Message/RestVerifyWebhookRequest.php index a915ae9..a4fc5e5 100644 --- a/src/Message/RestVerifyWebhookRequest.php +++ b/src/Message/RestVerifyWebhookRequest.php @@ -91,7 +91,16 @@ protected function getEndpoint() public function getData() { - $this->validate('authAlgo', 'certUrl', 'transmissionId', 'transmissionSig', 'transmissionTime', 'webhookId', 'webhookEvent'); + $this->validate( + 'authAlgo', + 'certUrl', + 'transmissionId', + 'transmissionSig', + 'transmissionTime', + 'webhookId', + 'webhookEvent' + ); + $data = array( 'auth_algo' => $this->getAuthAlgo(), 'cert_url' => $this->getCertUrl(),