Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from paypal/rel-reauth
Browse files Browse the repository at this point in the history
Reauthorization release
  • Loading branch information
ganeshx committed Jul 31, 2013
2 parents c61ee5b + 1bd1512 commit 4193ae1
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .coveralls.yml configuration

# for php-coveralls
src_dir: lib
coverage_clover: build/coverage/clover.xml
json_path: build/coverage/coveralls-upload.json
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ php:
- 5.4
- 5.3
before_script:
- composer install
- composer install --dev
- composer update satooshi/php-coveralls --dev
script:
- ant coverage
after_script:
- php vendor/bin/coveralls -v -c .coveralls.yml
notifications:
recipients:
- [email protected]
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGELOG
=========

V0.7.1 (July 31, 2013)
-----------------------
* Added support for Reauthorization

V0.7.0 (May 30, 2013)
-----------------------

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
REST API SDK for PHP (V0.7.0) [![Build Status](https://travis-ci.org/paypal/rest-api-sdk-php.png?branch=master)](https://travis-ci.org/paypal/rest-api-sdk-php)
==============================
REST API SDK for PHP
====================
[![Build Status](https://travis-ci.org/paypal/rest-api-sdk-php.png?branch=master)](https://travis-ci.org/paypal/rest-api-sdk-php) [![Coverage Status](https://coveralls.io/repos/paypal/rest-api-sdk-php/badge.png?branch=master)](https://coveralls.io/r/paypal/rest-api-sdk-php?branch=master) [![Latest Stable Version](https://poser.pugx.org/paypal/rest-api-sdk-php/v/stable.png)](https://packagist.org/packages/paypal/rest-api-sdk-php) [![Total Downloads](https://poser.pugx.org/paypal/rest-api-sdk-php/downloads.png)](https://packagist.org/packages/paypal/rest-api-sdk-php)

This repository contains PayPal's PHP SDK and samples for REST API.

Expand Down Expand Up @@ -64,5 +65,4 @@ More help
---------
* [API Reference](https://developer.paypal.com/webapps/developer/docs/api/)
* [Reporting issues / feature requests] (https://github.com/paypal/rest-api-sdk-php/issues)
* [Reporting issues / feature requests] (https://github.com/paypal/rest-api-sdk-php/issues)
14 changes: 6 additions & 8 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="paypal-rest-sdk-php" basedir="." default="all">

<property name="basedir" value="." />
<property name="release.dir" value="${basedir}/release" />
<property name="output.dir" value="${basedir}/build" />
<property name="phplint.out" value="${output.dir}/phplint.txt" />
Expand All @@ -9,9 +10,6 @@
<property name="coverage.out" value="${coverage.dir}/junit.xml" />
<property name="clover.out" value="${coverage.dir}/clover.xml" />
<property name="test.dir" value="${output.dir}/test" />
<property name="coverage.out" value="${coverage.dir}/junit.xml" />
<property name="clover.out" value="${coverage.dir}/clover.xml" />


<fileset id="src.files" dir="${basedir}/lib" includes="**/*.php" />

Expand All @@ -38,12 +36,12 @@
</target>

<target name="phploc">
<exec command="phploc.bat --log-xml ${phploc.out} ." dir="${basedir}/lib" />
<exec command="phploc --log-xml ${phploc.out} ." dir="${basedir}/lib" />
</target>

<target name="coverage">
<mkdir dir="${output.dir}/coverage"/>
<exec command="phpunit.bat --coverage-html=${coverage.dir} --coverage-clover=${clover.out} --log-junit=${coverage.out} --exclude-group=PayPal\\Api\\*" />
<exec command="phpunit --coverage-html=${coverage.dir} --coverage-clover=${clover.out} --log-junit=${coverage.out} --exclude-group=PayPal\\Api\\*" />
</target>

<target name="clean" description="Deletes build artifacts">
Expand All @@ -52,13 +50,13 @@
</target>

<target name="test" description="Runs test cases">
<exec command="phpunit.bat --testdox-html=${test.dir}/testdox.html --log-junit=${test.dir}/junit.xml"/>
<exec command="phpunit --testdox-html=${test.dir}/testdox.html --log-junit=${test.dir}/junit.xml"/>
</target>

<!-- Requires phing -->
<target name="convert-test-report">
<target name="convert-test-report" >
<mkdir dir="build/test/report"/>
<phpunitreport infile="build/test/junit.xml"
<phpunitreport infile="${coverage.out}"
format="frames"
todir="build/test/report" />
</target>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"paypal/sdk-core-php": "2.4.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
"phpunit/phpunit": "3.7.*",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"psr-0": {
Expand Down
8 changes: 4 additions & 4 deletions lib/PayPal/Api/CreditCardHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -19,7 +19,7 @@ public function setCreditCards($credit_cards) {
* @return PayPal\Api\CreditCard
*/
public function getCreditCards() {
return $this->credit-cards;
return $this->{"credit-cards"};
}

/**
Expand All @@ -29,7 +29,7 @@ public function getCreditCards() {
* @deprecated. Instead use setCreditCards
*/
public function setCredit_cards($credit_cards) {
$this->credit_cards = $credit_cards;
$this->{"credit-cards"} = $credit_cards;
return $this;
}
/**
Expand All @@ -38,7 +38,7 @@ public function setCredit_cards($credit_cards) {
* @deprecated. Instead use getCreditCards
*/
public function getCredit_cards() {
return $this->credit-cards;
return $this->{"credit-cards"};
}

/**
Expand Down
7 changes: 7 additions & 0 deletions sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ <h3>PayPal REST API Samples</h3>
<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>
Expand Down
42 changes: 42 additions & 0 deletions sample/payments/Reauthorization.php
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions sample/source/Reauthorization.html
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions tests/PayPal/Test/Api/AuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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();
Expand Down Expand Up @@ -137,4 +138,19 @@ public function testOperations() {
$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 changes: 72 additions & 0 deletions tests/PayPal/Test/Api/CreditCardHistoryTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 4193ae1

Please sign in to comment.