Helper Function to Retrieve Specific Link from Model Object

- Helper Methods in Payment and Agreement to get ApprovalLink
- Fixes #195
This commit is contained in:
japatel
2014-12-18 15:41:11 -06:00
parent d5450c64aa
commit f090642fae
12 changed files with 89 additions and 387 deletions

View File

@@ -28,7 +28,6 @@ use PayPal\Transport\PayPalRestCall;
* @property string create_time
* @property string update_time
* @property \PayPal\Api\AgreementDetails agreement_details
* @property \PayPal\Api\Links[] links
*/
class Agreement extends PayPalResourceModel
{
@@ -537,56 +536,13 @@ class Agreement extends PayPalResourceModel
}
/**
* Sets Links
* Get Approval Link
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
* @return null|string
*/
public function setLinks($links)
public function getApprovalLink()
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
return $this->getLink(Payment::APPROVAL_URL);
}
/**

View File

@@ -37,7 +37,6 @@ use PayPal\Transport\PayPalRestCall;
* @property string create_time
* @property string update_time
* @property string valid_until
* @property \PayPal\Api\Links[] links
*/
class BankAccount extends PayPalResourceModel
{
@@ -1101,59 +1100,6 @@ class BankAccount extends PayPalResourceModel
return $this->valid_until;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Creates a new Bank Account Resource.
*

View File

@@ -28,7 +28,6 @@ use PayPal\Transport\PayPalRestCall;
* @property string valid_until
* @property string create_time
* @property string update_time
* @property \PayPal\Api\Links[] links
*/
class CreditCard extends PayPalResourceModel
{
@@ -580,59 +579,6 @@ class CreditCard extends PayPalResourceModel
return $this->update_time;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Creates a new Credit Card Resource (aka Tokenize).
*

View File

@@ -26,11 +26,16 @@ use PayPal\Validation\ArgumentValidator;
* @property \PayPal\Api\Transaction[] transactions
* @property string state
* @property \PayPal\Api\RedirectUrls redirect_urls
* @property \PayPal\Api\Links links
* @property string experience_profile_id
*/
class Payment extends PayPalResourceModel
{
/**
* Approval URL for Payment
*/
const APPROVAL_URL = 'approval_url';
/**
* OAuth Credentials to use for this call
*
@@ -340,30 +345,6 @@ class Payment extends PayPalResourceModel
return $this->redirect_urls;
}
/**
* Sets Links
*
*
* @param \PayPal\Api\Links $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Set Experience_profile_id
* experience_profile_id of the payment
@@ -388,6 +369,16 @@ class Payment extends PayPalResourceModel
{
return $this->experience_profile_id;
}
/**
* Get Approval Link
*
* @return null|string
*/
public function getApprovalLink()
{
return $this->getLink(Payment::APPROVAL_URL);
}
/**
* Creates (and processes) a new Payment Resource.

View File

@@ -26,7 +26,6 @@ use PayPal\Transport\PayPalRestCall;
* @property \PayPal\Api\PaymentDefinition[] payment_definitions
* @property \PayPal\Api\Terms[] terms
* @property \PayPal\Api\MerchantPreferences merchant_preferences
* @property \PayPal\Api\Links[] links
*/
class Plan extends PayPalResourceModel
{
@@ -420,59 +419,6 @@ class Plan extends PayPalResourceModel
return $this->merchant_preferences;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Retrieve the details for a particular billing plan by passing the billing plan ID to the request URI.
*

View File

@@ -27,7 +27,6 @@ use PayPal\Validation\ArgumentValidator;
* @property string protection_eligibility_type
* @property string clearing_time
* @property string parent_payment
* @property \PayPal\Api\Links links
*/
class Sale extends PayPalResourceModel
{
@@ -562,30 +561,6 @@ class Sale extends PayPalResourceModel
return $this->parent_payment;
}
/**
* Sets Links
*
*
* @param \PayPal\Api\Links $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Obtain the Sale transaction resource for the given identifier.
*

View File

@@ -19,7 +19,6 @@ use PayPal\Validation\UrlValidator;
* @property string id
* @property string url
* @property \PayPal\Api\WebhookEventType[] event_types
* @property \PayPal\Api\Links[] links
*/
class Webhook extends PayPalResourceModel
{
@@ -148,58 +147,6 @@ class Webhook extends PayPalResourceModel
return $this->event_types;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Creates the Webhook for the application associated with the access token.

View File

@@ -22,7 +22,6 @@ use PayPal\Transport\PayPalRestCall;
* @property string event_type
* @property string summary
* @property mixed resource
* @property \PayPal\Api\Links[] links
*/
class WebhookEvent extends PayPalResourceModel
{
@@ -239,59 +238,6 @@ class WebhookEvent extends PayPalResourceModel
return $this->resource;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Retrieves the Webhooks event resource identified by event_id. Can be used to retrieve the payload for an event.
*

View File

@@ -11,6 +11,7 @@ use PayPal\Transport\PayPalRestCall;
* Class PayPalResourceModel
* An Executable PayPalModel Class
*
* @property \PayPal\Api\Links[] links
* @package PayPal\Common
*/
class PayPalResourceModel extends PayPalModel implements IResource
@@ -34,6 +35,69 @@ class PayPalResourceModel extends PayPalModel implements IResource
self::$credential = $credential;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
public function getLink($rel)
{
foreach ($this->links as $link) {
if ($link->getRel() == $rel) {
return $link->getHref();
}
}
return null;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Execute SDK Call to Paypal services

View File

@@ -71,14 +71,9 @@ try {
// ### Get redirect url
// The API response provides the url that you must redirect
// the buyer to. Retrieve the url from the $agreement->getLinks()
// the buyer to. Retrieve the url from the $agreement->getApprovalLink()
// method
foreach ($agreement->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
$approvalUrl = $agreement->getApprovalLink();
} catch (Exception $ex) {
ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex);

View File

@@ -108,12 +108,7 @@ try {
// The API response provides the url that you must redirect
// the buyer to. Retrieve the url from the $payment->getLinks()
// method
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
$approvalUrl = $payment->getApprovalLink();
ResultPrinter::printResult("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);

View File

@@ -104,14 +104,9 @@ try {
// ### Get redirect url
// The API response provides the url that you must redirect
// the buyer to. Retrieve the url from the $payment->getLinks()
// the buyer to. Retrieve the url from the $payment->getApprovalLink()
// method
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
$approvalUrl = $payment->getApprovalLink();
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);