forked from LiveCarta/PayPal-PHP-SDK
Merge pull request #16 from paypal/dev-reauth
updated CreditCardHistory.php, added sample and testcase for Reauthoriza...
This commit is contained in:
@@ -10,7 +10,7 @@ class CreditCardHistory extends PPModel {
|
||||
* @param PayPal\Api\CreditCard $credit-cards
|
||||
*/
|
||||
public function setCreditCards($credit_cards) {
|
||||
$this->credit_cards = $credit_cards;
|
||||
$this->{"credit-cards"} = $credit_cards;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class CreditCardHistory extends PPModel {
|
||||
* @return PayPal\Api\CreditCard
|
||||
*/
|
||||
public function getCreditCards() {
|
||||
return $this->credit-cards;
|
||||
return $this->{"credit-cards"};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ class CreditCardHistory extends PPModel {
|
||||
* @deprecated. Instead use setCreditCards
|
||||
*/
|
||||
public function setCredit_cards($credit_cards) {
|
||||
$this->credit_cards = $credit_cards;
|
||||
$this->{"credit-cards"} = $credit_cards;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class CreditCardHistory extends PPModel {
|
||||
* @deprecated. Instead use getCreditCards
|
||||
*/
|
||||
public function getCredit_cards() {
|
||||
return $this->credit-cards;
|
||||
return $this->{"credit-cards"};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -102,6 +102,13 @@
|
||||
<td></td>
|
||||
<td><a href="source/VoidAuthorization.html" class="source imagelink" >Source</a></td>
|
||||
</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>
|
||||
<td>Get Details of Captured Payment</td>
|
||||
<td></td>
|
||||
|
||||
42
sample/payments/Reauthorization.php
Normal file
42
sample/payments/Reauthorization.php
Normal 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>
|
||||
39
sample/source/Reauthorization.html
Normal file
39
sample/source/Reauthorization.html
Normal 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"><?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">'/../bootstrap.php'</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">'7GH53639GA425732B'</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">-></span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">"USD"</span><span class="p">);</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setTotal</span><span class="p">(</span><span class="s2">"1.00"</span><span class="p">);</span>
|
||||
|
||||
<span class="nv">$authorization</span><span class="o">-></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">-></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">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></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">-></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">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div></span>
|
||||
<span class="x"> Reauthorize:</span>
|
||||
<span class="x"> </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$reauthorization</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span><span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"> </div></span>
|
||||
<span class="x"> <pre></span>
|
||||
<span class="x"> </span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$reauthorization</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"> </pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></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>
|
||||
@@ -14,6 +14,7 @@ use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Exception\PPConnectionException;
|
||||
|
||||
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
|
||||
private $authorizations = array();
|
||||
@@ -137,4 +138,19 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
72
tests/PayPal/Test/Api/CreditCardHistoryTest.php
Normal file
72
tests/PayPal/Test/Api/CreditCardHistoryTest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user