updated CreditCardHistory.php, added sample and testcase for Reauthorization

This commit is contained in:
lathavairamani
2013-07-31 17:40:36 +05:30
parent e0046e3bbe
commit f1038717a7
6 changed files with 180 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ class CreditCardHistory extends PPModel {
* @param PayPal\Api\CreditCard $credit-cards * @param PayPal\Api\CreditCard $credit-cards
*/ */
public function setCreditCards($credit_cards) { public function setCreditCards($credit_cards) {
$this->credit_cards = $credit_cards; $this->{"credit-cards"} = $credit_cards;
return $this; return $this;
} }
@@ -19,7 +19,7 @@ class CreditCardHistory extends PPModel {
* @return PayPal\Api\CreditCard * @return PayPal\Api\CreditCard
*/ */
public function getCreditCards() { public function getCreditCards() {
return $this->credit-cards; return $this->{"credit-cards"};
} }
/** /**
@@ -29,7 +29,7 @@ class CreditCardHistory extends PPModel {
* @deprecated. Instead use setCreditCards * @deprecated. Instead use setCreditCards
*/ */
public function setCredit_cards($credit_cards) { public function setCredit_cards($credit_cards) {
$this->credit_cards = $credit_cards; $this->{"credit-cards"} = $credit_cards;
return $this; return $this;
} }
/** /**
@@ -38,7 +38,7 @@ class CreditCardHistory extends PPModel {
* @deprecated. Instead use getCreditCards * @deprecated. Instead use getCreditCards
*/ */
public function getCredit_cards() { public function getCredit_cards() {
return $this->credit-cards; return $this->{"credit-cards"};
} }
/** /**

View File

@@ -102,6 +102,13 @@
<td></td> <td></td>
<td><a href="source/VoidAuthorization.html" class="source imagelink" >Source</a></td> <td><a href="source/VoidAuthorization.html" class="source imagelink" >Source</a></td>
</tr> </tr>
<tr>
<td>Reauthorize a Payment</td>
<td></td>
<td><a href="payments/Reauthorization.php" class="execute imagelink" >Execute</a></td>
<td></td>
<td><a href="source/Reauthorization.html" class="source imagelink" >Source</a></td>
</tr>
<tr> <tr>
<td>Get Details of Captured Payment</td> <td>Get Details of Captured Payment</td>
<td></td> <td></td>

View File

@@ -0,0 +1,42 @@
<?php
// ##Reauthorization Sample
// Sample showing how to do a reauthorization
// API used: v1/payments/authorization/{authorization_id}/reauthorize
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Authorization;
use PayPal\Api\Amount;
use PayPal\Exception\PPConnectionException;
// ###Reauthorization
// Retrieve a authorization id from authorization object
// by making a `Payment Using PayPal` with intent
// as `authorize`. You can reauthorize a payment only once 4 to 29
// days after 3-day honor period for the original authorization
// expires.
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try{
$reauthorization = $authorization->reauthorize($apiContext);
}catch (PPConnectionException $ex){
echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
?>
<html>
<body>
<div>
Reauthorize:
<?php echo $reauthorization->getId();?>
</div>
<pre>
<?php var_dump($reauthorization->toArray());?>
</pre>
<a href='../index.html'>Back</a>
</body>
</html>

View File

@@ -0,0 +1,39 @@
<!DOCTYPE html><html lang="en"><head><title>Reauthorization</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="Reauthorization"><meta name="groc-project-path" content="Reauthorization.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body></body></html><a href="../">Back<div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp">&lt;?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow"></a></div><div class="wrapper"><h2 id="reauthorization-sample">Reauthorization Sample</h2>
<p>Sample showing how to do a reauthorization
API used: v1/payments/authorization/{authorization_id}/reauthorize</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Authorization</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Exception\PPConnectionException</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow"></a></div><div class="wrapper"><h3 id="reauthorization">Reauthorization</h3>
<p>Retrieve a authorization id from authorization object
by making a <code>Payment Using PayPal</code> with intent
as <code>authorize</code>. You can reauthorize a payment only once 4 to 29
days after 3-day honor period for the original authorization
expires.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$authorization</span> <span class="o">=</span> <span class="nx">Authorization</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="s1">&#39;7GH53639GA425732B&#39;</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
<span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span>
<span class="nv">$authorization</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
<span class="k">try</span><span class="p">{</span>
<span class="nv">$reauthorization</span> <span class="o">=</span> <span class="nv">$authorization</span><span class="o">-&gt;</span><span class="na">reauthorize</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
<span class="p">}</span><span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">){</span>
<span class="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span>
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;html&gt;</span>
<span class="x">&lt;body&gt;</span>
<span class="x"> &lt;div&gt;</span>
<span class="x"> Reauthorize:</span>
<span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$reauthorization</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x"></span>
<span class="x"> &lt;/div&gt;</span>
<span class="x"> &lt;pre&gt;</span>
<span class="x"> </span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$reauthorization</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x"></span>
<span class="x"> &lt;/pre&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></a>

View File

@@ -14,6 +14,7 @@ use PayPal\Api\Payer;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument; use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
use PayPal\Exception\PPConnectionException;
class AuthorizationTest extends \PHPUnit_Framework_TestCase { class AuthorizationTest extends \PHPUnit_Framework_TestCase {
private $authorizations = array(); private $authorizations = array();
@@ -137,4 +138,19 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
$this->assertNotNull($void->getId()); $this->assertNotNull($void->getId());
} }
public function testReauthorize(){
$authorization = Authorization::get('7GH53639GA425732B');
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try{
$reauthorization = $authorization->reauthorize();
}catch (PPConnectionException $ex){
$this->assertEquals(strpos($ex->getMessage(),"500"), false);
}
}
} }

View File

@@ -0,0 +1,72 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\CreditCardHistory;
use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Test\Constants;
class CreditCardHistoryTest extends \PHPUnit_Framework_TestCase {
private $cards;
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public static function createCreditCard() {
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpireMonth(self::$expireMonth);
$card->setExpireYear(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirstName(self::$firstName);
$card->setLastName(self::$lastName);
$card->setId(self::$id);
$card->setValidUntil(self::$validUntil);
$card->setState(self::$state);
$card->setPayerId(self::$payerId);
return $card;
}
public function setup() {
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
public function testGetterSetters() {
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$this->assertEquals(2, count($cardHistory->getCreditCards()));
}
public function testSerializationDeserialization() {
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$cardHistoryCopy = new CreditCardHistory();
$cardHistoryCopy->fromJson($cardHistory->toJSON());
$this->assertEquals($cardHistory, $cardHistoryCopy);
}
}