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 create_time
* @property string update_time * @property string update_time
* @property \PayPal\Api\AgreementDetails agreement_details * @property \PayPal\Api\AgreementDetails agreement_details
* @property \PayPal\Api\Links[] links
*/ */
class Agreement extends PayPalResourceModel class Agreement extends PayPalResourceModel
{ {
@@ -537,56 +536,13 @@ class Agreement extends PayPalResourceModel
} }
/** /**
* Sets Links * Get Approval Link
* *
* @param \PayPal\Api\Links[] $links * @return null|string
*
* @return $this
*/ */
public function setLinks($links) public function getApprovalLink()
{ {
$this->links = $links; return $this->getLink(Payment::APPROVAL_URL);
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))
);
} }
/** /**

View File

@@ -37,7 +37,6 @@ use PayPal\Transport\PayPalRestCall;
* @property string create_time * @property string create_time
* @property string update_time * @property string update_time
* @property string valid_until * @property string valid_until
* @property \PayPal\Api\Links[] links
*/ */
class BankAccount extends PayPalResourceModel class BankAccount extends PayPalResourceModel
{ {
@@ -1101,59 +1100,6 @@ class BankAccount extends PayPalResourceModel
return $this->valid_until; 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. * Creates a new Bank Account Resource.
* *

View File

@@ -28,7 +28,6 @@ use PayPal\Transport\PayPalRestCall;
* @property string valid_until * @property string valid_until
* @property string create_time * @property string create_time
* @property string update_time * @property string update_time
* @property \PayPal\Api\Links[] links
*/ */
class CreditCard extends PayPalResourceModel class CreditCard extends PayPalResourceModel
{ {
@@ -580,59 +579,6 @@ class CreditCard extends PayPalResourceModel
return $this->update_time; 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). * Creates a new Credit Card Resource (aka Tokenize).
* *

View File

@@ -26,11 +26,16 @@ use PayPal\Validation\ArgumentValidator;
* @property \PayPal\Api\Transaction[] transactions * @property \PayPal\Api\Transaction[] transactions
* @property string state * @property string state
* @property \PayPal\Api\RedirectUrls redirect_urls * @property \PayPal\Api\RedirectUrls redirect_urls
* @property \PayPal\Api\Links links
* @property string experience_profile_id * @property string experience_profile_id
*/ */
class Payment extends PayPalResourceModel class Payment extends PayPalResourceModel
{ {
/**
* Approval URL for Payment
*/
const APPROVAL_URL = 'approval_url';
/** /**
* OAuth Credentials to use for this call * OAuth Credentials to use for this call
* *
@@ -340,30 +345,6 @@ class Payment extends PayPalResourceModel
return $this->redirect_urls; 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 * Set Experience_profile_id
* experience_profile_id of the payment * experience_profile_id of the payment
@@ -388,6 +369,16 @@ class Payment extends PayPalResourceModel
{ {
return $this->experience_profile_id; 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. * 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\PaymentDefinition[] payment_definitions
* @property \PayPal\Api\Terms[] terms * @property \PayPal\Api\Terms[] terms
* @property \PayPal\Api\MerchantPreferences merchant_preferences * @property \PayPal\Api\MerchantPreferences merchant_preferences
* @property \PayPal\Api\Links[] links
*/ */
class Plan extends PayPalResourceModel class Plan extends PayPalResourceModel
{ {
@@ -420,59 +419,6 @@ class Plan extends PayPalResourceModel
return $this->merchant_preferences; 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. * 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 protection_eligibility_type
* @property string clearing_time * @property string clearing_time
* @property string parent_payment * @property string parent_payment
* @property \PayPal\Api\Links links
*/ */
class Sale extends PayPalResourceModel class Sale extends PayPalResourceModel
{ {
@@ -562,30 +561,6 @@ class Sale extends PayPalResourceModel
return $this->parent_payment; 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. * Obtain the Sale transaction resource for the given identifier.
* *

View File

@@ -19,7 +19,6 @@ use PayPal\Validation\UrlValidator;
* @property string id * @property string id
* @property string url * @property string url
* @property \PayPal\Api\WebhookEventType[] event_types * @property \PayPal\Api\WebhookEventType[] event_types
* @property \PayPal\Api\Links[] links
*/ */
class Webhook extends PayPalResourceModel class Webhook extends PayPalResourceModel
{ {
@@ -148,58 +147,6 @@ class Webhook extends PayPalResourceModel
return $this->event_types; 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. * 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 event_type
* @property string summary * @property string summary
* @property mixed resource * @property mixed resource
* @property \PayPal\Api\Links[] links
*/ */
class WebhookEvent extends PayPalResourceModel class WebhookEvent extends PayPalResourceModel
{ {
@@ -239,59 +238,6 @@ class WebhookEvent extends PayPalResourceModel
return $this->resource; 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. * 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 * Class PayPalResourceModel
* An Executable PayPalModel Class * An Executable PayPalModel Class
* *
* @property \PayPal\Api\Links[] links
* @package PayPal\Common * @package PayPal\Common
*/ */
class PayPalResourceModel extends PayPalModel implements IResource class PayPalResourceModel extends PayPalModel implements IResource
@@ -34,6 +35,69 @@ class PayPalResourceModel extends PayPalModel implements IResource
self::$credential = $credential; 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 * Execute SDK Call to Paypal services

View File

@@ -71,14 +71,9 @@ try {
// ### Get redirect url // ### Get redirect url
// The API response provides the url that you must redirect // 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 // method
foreach ($agreement->getLinks() as $link) { $approvalUrl = $agreement->getApprovalLink();
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
} catch (Exception $ex) { } catch (Exception $ex) {
ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $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 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->getLinks()
// method // method
foreach ($payment->getLinks() as $link) { $approvalUrl = $payment->getApprovalLink();
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
ResultPrinter::printResult("Created Payment Authorization Using PayPal. Please visit the URL to Authorize.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); 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 // ### Get redirect url
// The API response provides the url that you must redirect // 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 // method
foreach ($payment->getLinks() as $link) { $approvalUrl = $payment->getApprovalLink();
if ($link->getRel() == 'approval_url') {
$approvalUrl = $link->getHref();
break;
}
}
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);