forked from LiveCarta/PayPal-PHP-SDK
Initial commit
This commit is contained in:
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
build
|
||||||
|
.DS_Store
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.buildpath
|
||||||
|
*.bak
|
||||||
|
|
||||||
|
# Composer
|
||||||
|
vendor
|
||||||
|
composer.lock
|
||||||
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
CHANGELOG
|
||||||
|
=========
|
||||||
|
|
||||||
|
V0.5.0 (March 07, 2013)
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
* Initial Release
|
||||||
41
LICENSE.txt
Normal file
41
LICENSE.txt
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
PAYPAL, INC.
|
||||||
|
|
||||||
|
SDK LICENSE
|
||||||
|
|
||||||
|
NOTICE TO USER: PayPal, Inc. is providing the Software and Documentation for use under the terms of this Agreement. Any use, reproduction, modification or distribution of the Software or Documentation, or any derivatives or portions hereof, constitutes your acceptance of this Agreement.
|
||||||
|
|
||||||
|
As used in this Agreement, "PayPal" means PayPal, Inc. "Software" means the software code accompanying this agreement. "Documentation" means the documents, specifications and all other items accompanying this Agreement other than the Software.
|
||||||
|
|
||||||
|
1. LICENSE GRANT Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, worldwide, royalty free license to use, reproduce, prepare derivative works from, publicly display, publicly perform, distribute and sublicense the Software for any purpose, provided the copyright notice below appears in a conspicuous location within the source code of the distributed Software and this license is distributed in the supporting documentation of the Software you distribute. Furthermore, you must comply with all third party licenses in order to use the third party software contained in the Software.
|
||||||
|
|
||||||
|
Subject to the terms of this Agreement, PayPal hereby grants you a non-exclusive, worldwide, royalty free license to use, reproduce, publicly display, publicly perform, distribute and sublicense the Documentation for any purpose. You may not modify the Documentation.
|
||||||
|
|
||||||
|
No title to the intellectual property in the Software or Documentation is transferred to you under the terms of this Agreement. You do not acquire any rights to the Software or the Documentation except as expressly set forth in this Agreement.
|
||||||
|
|
||||||
|
If you choose to distribute the Software in a commercial product, you do so with the understanding that you agree to defend, indemnify and hold harmless PayPal and its suppliers against any losses, damages and costs arising from the claims, lawsuits or other legal actions arising out of such distribution. You may distribute the Software in object code form under your own license, provided that your license agreement:
|
||||||
|
|
||||||
|
(a) complies with the terms and conditions of this license agreement;
|
||||||
|
|
||||||
|
(b) effectively disclaims all warranties and conditions, express or implied, on behalf of PayPal;
|
||||||
|
|
||||||
|
(c) effectively excludes all liability for damages on behalf of PayPal;
|
||||||
|
|
||||||
|
(d) states that any provisions that differ from this Agreement are offered by you alone and not PayPal; and
|
||||||
|
|
||||||
|
(e) states that the Software is available from you or PayPal and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
|
||||||
|
|
||||||
|
2. DISCLAIMER OF WARRANTY
|
||||||
|
PAYPAL LICENSES THE SOFTWARE AND DOCUMENTATION TO YOU ONLY ON AN "AS IS" BASIS WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. PAYPAL MAKES NO WARRANTY THAT THE SOFTWARE OR DOCUMENTATION WILL BE ERROR-FREE. Each user of the Software or Documentation is solely responsible for determining the appropriateness of using and distributing the Software and Documentation and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs, or equipment, and unavailability or interruption of operations. Use of the Software and Documentation is made with the understanding that PayPal will not provide you with any technical or customer support or maintenance. Some states or jurisdictions do not allow the exclusion of implied warranties or limitations on how long an implied warranty may last, so the above limitations may not apply to you. To the extent permissible, any implied warranties are limited to ninety (90) days.
|
||||||
|
|
||||||
|
|
||||||
|
3. LIMITATION OF LIABILITY
|
||||||
|
PAYPAL AND ITS SUPPLIERS SHALL NOT BE LIABLE FOR LOSS OR DAMAGE ARISING OUT OF THIS AGREEMENT OR FROM THE USE OF THE SOFTWARE OR DOCUMENTATION. IN NO EVENT WILL PAYPAL OR ITS SUPPLIERS BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES INCLUDING LOST PROFITS, LOST SAVINGS, COSTS, FEES, OR EXPENSES OF ANY KIND ARISING OUT OF ANY PROVISION OF THIS AGREEMENT OR THE USE OR THE INABILITY TO USE THE SOFTWARE OR DOCUMENTATION, HOWEVER CAUSED AND UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. PAYPAL'S AGGREGATE LIABILITY AND THAT OF ITS SUPPLIERS UNDER OR IN CONNECTION WITH THIS AGREEMENT SHALL BE LIMITED TO THE AMOUNT PAID BY YOU FOR THE SOFTWARE AND DOCUMENTATION.
|
||||||
|
|
||||||
|
4. TRADEMARK USAGE
|
||||||
|
PayPal is a trademark PayPal, Inc. in the United States and other countries. Such trademarks may not be used to endorse or promote any product unless expressly permitted under separate agreement with PayPal.
|
||||||
|
|
||||||
|
5. TERM
|
||||||
|
Your rights under this Agreement shall terminate if you fail to comply with any of the material terms or conditions of this Agreement and do not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all your rights under this Agreement terminate, you agree to cease use and distribution of the Software and Documentation as soon as reasonably practicable.
|
||||||
|
|
||||||
|
6. GOVERNING LAW AND JURISDICTION. This Agreement is governed by the statutes and laws of the State of California, without regard to the conflicts of law principles thereof. If any part of this Agreement is found void and unenforceable, it will not affect the validity of the balance of the Agreement, which shall remain valid and enforceable according to its terms. Any dispute arising out of or related to this Agreement shall be brought in the courts of Santa Clara County, California, USA.
|
||||||
|
|
||||||
61
README.md
Normal file
61
README.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
REST API SDK for PHP (V0.5.0)
|
||||||
|
==============================
|
||||||
|
|
||||||
|
PayPal's PHP SDK for the RESTful APIs
|
||||||
|
|
||||||
|
|
||||||
|
Prerequisites
|
||||||
|
-------------
|
||||||
|
|
||||||
|
* PHP 5.3 or above
|
||||||
|
* curl, json & openssl extensions must be enabled
|
||||||
|
* composer for running the sample out of the box (See http://getcomposer.org)
|
||||||
|
|
||||||
|
|
||||||
|
Running the sample
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* Ensure that you have composer installed on your machine.
|
||||||
|
* Navigate to the samples folder and run 'composer update'.
|
||||||
|
* Optionally, update the sdk_config.ini file with your own client Id and client secret.
|
||||||
|
* Run any of the command line samples in the folder to see what the APIs can do.
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
To write an app that uses the SDK
|
||||||
|
|
||||||
|
* Copy the composer.json file from the sample folder over to your project and run 'composer update' to fetch all
|
||||||
|
dependencies
|
||||||
|
* Copy the sample configuration file sdk_config.ini to a location of your choice and let the SDK know your config path using the following define directive
|
||||||
|
|
||||||
|
define('PP_SDK_CONFIG_PATH', /path/to/your/sdk_config.ini);
|
||||||
|
|
||||||
|
* Obtain your clientId and client secret from the developer portal and add them to your config file
|
||||||
|
* Now you are all set to make your first API call. Create a resource object as per your need and call the relevant operation or invoke one of the static methods on your resource class.
|
||||||
|
|
||||||
|
$payment = new Payment();
|
||||||
|
|
||||||
|
$payment->setIntent("Sale");
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
$payment->create();
|
||||||
|
|
||||||
|
*OR*
|
||||||
|
|
||||||
|
$payment = Payment::get('payment_id');
|
||||||
|
|
||||||
|
These examples pick the client id / secret automatically from your config file. You can also set API credentials dynamically. See the sample code for how you can do this.
|
||||||
|
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
------------
|
||||||
|
|
||||||
|
More help
|
||||||
|
---------
|
||||||
|
|
||||||
|
* API Reference
|
||||||
|
* Reporting issues / feature requests
|
||||||
|
|
||||||
69
build.xml
Normal file
69
build.xml
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project name="paypal-rest-sdk-php" basedir="." default="all">
|
||||||
|
|
||||||
|
<property name="release.dir" value="${basedir}/release" />
|
||||||
|
<property name="output.dir" value="${basedir}/build" />
|
||||||
|
<property name="phplint.out" value="${output.dir}/phplint.txt" />
|
||||||
|
<property name="phploc.out" value="${output.dir}/phploc.xml" />
|
||||||
|
<property name="coverage.dir" value="${output.dir}/coverage" />
|
||||||
|
<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" />
|
||||||
|
|
||||||
|
<target name="composer-init" description="Downloads composer.phar if not available locally">
|
||||||
|
<if>
|
||||||
|
<available file="composer.phar" />
|
||||||
|
<then>
|
||||||
|
<echo>Composer is installed</echo>
|
||||||
|
</then>
|
||||||
|
<else>
|
||||||
|
<echo message="Installing composer" />
|
||||||
|
<exec command="curl -s http://getcomposer.org/installer | php" />
|
||||||
|
<exec command="php composer.phar install --dev" />
|
||||||
|
</else>
|
||||||
|
</if>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="phplint">
|
||||||
|
<delete file="${phplint.out}"/>
|
||||||
|
<apply executable="php" failonerror="true" output="${phplint.out}" append="true">
|
||||||
|
<arg value="-l" />
|
||||||
|
<fileset refid="src.files" />
|
||||||
|
</apply>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="phploc">
|
||||||
|
<exec command="phploc.bat --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\\*" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="clean" description="Deletes build artifacts">
|
||||||
|
<delete dir="${output.dir}"/>
|
||||||
|
<mkdir dir="${output.dir}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="test" description="Runs test cases">
|
||||||
|
<exec command="phpunit.bat --testdox-html=${test.dir}/testdox.html --log-junit=${test.dir}/junit.xml"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Requires phing -->
|
||||||
|
<target name="convert-test-report">
|
||||||
|
<mkdir dir="build/test/report"/>
|
||||||
|
<phpunitreport infile="build/test/junit.xml"
|
||||||
|
format="frames"
|
||||||
|
todir="build/test/report" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="build" depends="test" description="Builds SDK" />
|
||||||
|
<target name="report" depends="phplint, coverage, phploc" description="Runs code checks and coverage reports" />
|
||||||
|
<target name="all" depends="clean, test, build, report" description="Do everything" />
|
||||||
|
</project>
|
||||||
21
composer.json
Normal file
21
composer.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "paypal/rest-api-sdk-php",
|
||||||
|
"description": "PayPal's PHP SDK for REST APIs",
|
||||||
|
"keywords": ["paypal", "payments", "rest", "sdk"],
|
||||||
|
"type": "library",
|
||||||
|
"homepage": "https://github.com/paypal/rest-api-sdk-php",
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0",
|
||||||
|
"ext-curl": "*",
|
||||||
|
"ext-json": "*",
|
||||||
|
"paypal/sdk-core-php": "1.2.*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "3.7.*"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"PayPal": "lib/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
132
lib/PayPal/Api/Address.php
Normal file
132
lib/PayPal/Api/Address.php
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Address extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for line1
|
||||||
|
* @param string $line1
|
||||||
|
*/
|
||||||
|
public function setLine1($line1) {
|
||||||
|
$this->line1 = $line1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for line1
|
||||||
|
*/
|
||||||
|
public function getLine1() {
|
||||||
|
return $this->line1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for line2
|
||||||
|
* @param string $line2
|
||||||
|
*/
|
||||||
|
public function setLine2($line2) {
|
||||||
|
$this->line2 = $line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for line2
|
||||||
|
*/
|
||||||
|
public function getLine2() {
|
||||||
|
return $this->line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for city
|
||||||
|
* @param string $city
|
||||||
|
*/
|
||||||
|
public function setCity($city) {
|
||||||
|
$this->city = $city;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for city
|
||||||
|
*/
|
||||||
|
public function getCity() {
|
||||||
|
return $this->city;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for postal_code
|
||||||
|
* @param string $postal_code
|
||||||
|
*/
|
||||||
|
public function setPostal_code($postal_code) {
|
||||||
|
$this->postal_code = $postal_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for postal_code
|
||||||
|
*/
|
||||||
|
public function getPostal_code() {
|
||||||
|
return $this->postal_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for country_code
|
||||||
|
* @param string $country_code
|
||||||
|
*/
|
||||||
|
public function setCountry_code($country_code) {
|
||||||
|
$this->country_code = $country_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for country_code
|
||||||
|
*/
|
||||||
|
public function getCountry_code() {
|
||||||
|
return $this->country_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for type
|
||||||
|
* @param string $type
|
||||||
|
*/
|
||||||
|
public function setType($type) {
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for type
|
||||||
|
*/
|
||||||
|
public function getType() {
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for phone
|
||||||
|
* @param string $phone
|
||||||
|
*/
|
||||||
|
public function setPhone($phone) {
|
||||||
|
$this->phone = $phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for phone
|
||||||
|
*/
|
||||||
|
public function getPhone() {
|
||||||
|
return $this->phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
57
lib/PayPal/Api/Amount.php
Normal file
57
lib/PayPal/Api/Amount.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Amount extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for total
|
||||||
|
* @param string $total
|
||||||
|
*/
|
||||||
|
public function setTotal($total) {
|
||||||
|
$this->total = $total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for total
|
||||||
|
*/
|
||||||
|
public function getTotal() {
|
||||||
|
return $this->total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for currency
|
||||||
|
* @param string $currency
|
||||||
|
*/
|
||||||
|
public function setCurrency($currency) {
|
||||||
|
$this->currency = $currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for currency
|
||||||
|
*/
|
||||||
|
public function getCurrency() {
|
||||||
|
return $this->currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for details
|
||||||
|
* @param PayPal\Api\AmountDetails $details
|
||||||
|
*/
|
||||||
|
public function setDetails($details) {
|
||||||
|
$this->details = $details;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for details
|
||||||
|
*/
|
||||||
|
public function getDetails() {
|
||||||
|
return $this->details;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
72
lib/PayPal/Api/AmountDetails.php
Normal file
72
lib/PayPal/Api/AmountDetails.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class AmountDetails extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for subtotal
|
||||||
|
* @param string $subtotal
|
||||||
|
*/
|
||||||
|
public function setSubtotal($subtotal) {
|
||||||
|
$this->subtotal = $subtotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for subtotal
|
||||||
|
*/
|
||||||
|
public function getSubtotal() {
|
||||||
|
return $this->subtotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for tax
|
||||||
|
* @param string $tax
|
||||||
|
*/
|
||||||
|
public function setTax($tax) {
|
||||||
|
$this->tax = $tax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for tax
|
||||||
|
*/
|
||||||
|
public function getTax() {
|
||||||
|
return $this->tax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for shipping
|
||||||
|
* @param string $shipping
|
||||||
|
*/
|
||||||
|
public function setShipping($shipping) {
|
||||||
|
$this->shipping = $shipping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for shipping
|
||||||
|
*/
|
||||||
|
public function getShipping() {
|
||||||
|
return $this->shipping;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for fee
|
||||||
|
* @param string $fee
|
||||||
|
*/
|
||||||
|
public function setFee($fee) {
|
||||||
|
$this->fee = $fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for fee
|
||||||
|
*/
|
||||||
|
public function getFee() {
|
||||||
|
return $this->fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
117
lib/PayPal/Api/Authorization.php
Normal file
117
lib/PayPal/Api/Authorization.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Authorization extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for id
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for id
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for create_time
|
||||||
|
* @param string $create_time
|
||||||
|
*/
|
||||||
|
public function setCreate_time($create_time) {
|
||||||
|
$this->create_time = $create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for create_time
|
||||||
|
*/
|
||||||
|
public function getCreate_time() {
|
||||||
|
return $this->create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for update_time
|
||||||
|
* @param string $update_time
|
||||||
|
*/
|
||||||
|
public function setUpdate_time($update_time) {
|
||||||
|
$this->update_time = $update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for update_time
|
||||||
|
*/
|
||||||
|
public function getUpdate_time() {
|
||||||
|
return $this->update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for amount
|
||||||
|
* @param PayPal\Api\Amount $amount
|
||||||
|
*/
|
||||||
|
public function setAmount($amount) {
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for amount
|
||||||
|
*/
|
||||||
|
public function getAmount() {
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for parent_payment
|
||||||
|
* @param string $parent_payment
|
||||||
|
*/
|
||||||
|
public function setParent_payment($parent_payment) {
|
||||||
|
$this->parent_payment = $parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for parent_payment
|
||||||
|
*/
|
||||||
|
public function getParent_payment() {
|
||||||
|
return $this->parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for links
|
||||||
|
* @param PayPal\Api\Link $links
|
||||||
|
*/
|
||||||
|
public function setLinks($links) {
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for links
|
||||||
|
*/
|
||||||
|
public function getLinks() {
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
147
lib/PayPal/Api/Capture.php
Normal file
147
lib/PayPal/Api/Capture.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Capture extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for id
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for id
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for create_time
|
||||||
|
* @param string $create_time
|
||||||
|
*/
|
||||||
|
public function setCreate_time($create_time) {
|
||||||
|
$this->create_time = $create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for create_time
|
||||||
|
*/
|
||||||
|
public function getCreate_time() {
|
||||||
|
return $this->create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for update_time
|
||||||
|
* @param string $update_time
|
||||||
|
*/
|
||||||
|
public function setUpdate_time($update_time) {
|
||||||
|
$this->update_time = $update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for update_time
|
||||||
|
*/
|
||||||
|
public function getUpdate_time() {
|
||||||
|
return $this->update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for amount
|
||||||
|
* @param PayPal\Api\Amount $amount
|
||||||
|
*/
|
||||||
|
public function setAmount($amount) {
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for amount
|
||||||
|
*/
|
||||||
|
public function getAmount() {
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for parent_payment
|
||||||
|
* @param string $parent_payment
|
||||||
|
*/
|
||||||
|
public function setParent_payment($parent_payment) {
|
||||||
|
$this->parent_payment = $parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for parent_payment
|
||||||
|
*/
|
||||||
|
public function getParent_payment() {
|
||||||
|
return $this->parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for authorization_id
|
||||||
|
* @param string $authorization_id
|
||||||
|
*/
|
||||||
|
public function setAuthorization_id($authorization_id) {
|
||||||
|
$this->authorization_id = $authorization_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for authorization_id
|
||||||
|
*/
|
||||||
|
public function getAuthorization_id() {
|
||||||
|
return $this->authorization_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for description
|
||||||
|
* @param string $description
|
||||||
|
*/
|
||||||
|
public function setDescription($description) {
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for description
|
||||||
|
*/
|
||||||
|
public function getDescription() {
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for links
|
||||||
|
* @param PayPal\Api\Link $links
|
||||||
|
*/
|
||||||
|
public function setLinks($links) {
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for links
|
||||||
|
*/
|
||||||
|
public function getLinks() {
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
253
lib/PayPal/Api/CreditCard.php
Normal file
253
lib/PayPal/Api/CreditCard.php
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
use PayPal\Rest\IResource;
|
||||||
|
use PayPal\Rest\Call;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CreditCard extends Resource implements IResource {
|
||||||
|
|
||||||
|
private static $credential;
|
||||||
|
|
||||||
|
public static function setCredential($credential) {
|
||||||
|
self::$credential = $credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for id
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for id
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for valid_until
|
||||||
|
* @param string $valid_until
|
||||||
|
*/
|
||||||
|
public function setValid_until($valid_until) {
|
||||||
|
$this->valid_until = $valid_until;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for valid_until
|
||||||
|
*/
|
||||||
|
public function getValid_until() {
|
||||||
|
return $this->valid_until;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payer_id
|
||||||
|
* @param string $payer_id
|
||||||
|
*/
|
||||||
|
public function setPayer_id($payer_id) {
|
||||||
|
$this->payer_id = $payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payer_id
|
||||||
|
*/
|
||||||
|
public function getPayer_id() {
|
||||||
|
return $this->payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for type
|
||||||
|
* @param string $type
|
||||||
|
*/
|
||||||
|
public function setType($type) {
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for type
|
||||||
|
*/
|
||||||
|
public function getType() {
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for number
|
||||||
|
* @param string $number
|
||||||
|
*/
|
||||||
|
public function setNumber($number) {
|
||||||
|
$this->number = $number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for number
|
||||||
|
*/
|
||||||
|
public function getNumber() {
|
||||||
|
return $this->number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for expire_month
|
||||||
|
* @param string $expire_month
|
||||||
|
*/
|
||||||
|
public function setExpire_month($expire_month) {
|
||||||
|
$this->expire_month = $expire_month;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for expire_month
|
||||||
|
*/
|
||||||
|
public function getExpire_month() {
|
||||||
|
return $this->expire_month;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for expire_year
|
||||||
|
* @param string $expire_year
|
||||||
|
*/
|
||||||
|
public function setExpire_year($expire_year) {
|
||||||
|
$this->expire_year = $expire_year;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for expire_year
|
||||||
|
*/
|
||||||
|
public function getExpire_year() {
|
||||||
|
return $this->expire_year;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for cvv2
|
||||||
|
* @param string $cvv2
|
||||||
|
*/
|
||||||
|
public function setCvv2($cvv2) {
|
||||||
|
$this->cvv2 = $cvv2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for cvv2
|
||||||
|
*/
|
||||||
|
public function getCvv2() {
|
||||||
|
return $this->cvv2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for first_name
|
||||||
|
* @param string $first_name
|
||||||
|
*/
|
||||||
|
public function setFirst_name($first_name) {
|
||||||
|
$this->first_name = $first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for first_name
|
||||||
|
*/
|
||||||
|
public function getFirst_name() {
|
||||||
|
return $this->first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for last_name
|
||||||
|
* @param string $last_name
|
||||||
|
*/
|
||||||
|
public function setLast_name($last_name) {
|
||||||
|
$this->last_name = $last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for last_name
|
||||||
|
*/
|
||||||
|
public function getLast_name() {
|
||||||
|
return $this->last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for billing_address
|
||||||
|
* @param PayPal\Api\Address $billing_address
|
||||||
|
*/
|
||||||
|
public function setBilling_address($billing_address) {
|
||||||
|
$this->billing_address = $billing_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for billing_address
|
||||||
|
*/
|
||||||
|
public function getBilling_address() {
|
||||||
|
return $this->billing_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for links
|
||||||
|
* @param PayPal\Api\Link $links
|
||||||
|
*/
|
||||||
|
public function setLinks($links) {
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for links
|
||||||
|
*/
|
||||||
|
public function getLinks() {
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/vault/credit-card
|
||||||
|
* @method POST
|
||||||
|
|
||||||
|
* @param PayPal\Rest\ApiContext $apiContext optional
|
||||||
|
*/
|
||||||
|
public function create( $apiContext=null) {
|
||||||
|
$payLoad = $this->toJSON();
|
||||||
|
if($apiContext == null) {
|
||||||
|
$apiContext = new ApiContext(self::$credential);
|
||||||
|
}
|
||||||
|
$call = new Call();
|
||||||
|
$json = $call->execute("/v1/vault/credit-card", "POST", $payLoad, $apiContext);
|
||||||
|
$this->fromJson($json);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/vault/credit-card/:credit-card-id
|
||||||
|
* @method GET
|
||||||
|
* @param string $creditcardid
|
||||||
|
*/
|
||||||
|
public static function get( $creditcardid) {
|
||||||
|
if (($creditcardid == null) || (strlen($creditcardid) <= 0)) {
|
||||||
|
throw new \InvalidArgumentException("creditcardid cannot be null or empty");
|
||||||
|
}
|
||||||
|
$payLoad = "";
|
||||||
|
|
||||||
|
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||||
|
$json = $call->execute("/v1/vault/credit-card/$creditcardid", "GET", $payLoad, $apiContext);
|
||||||
|
$ret = new CreditCard();
|
||||||
|
$ret->fromJson($json);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
42
lib/PayPal/Api/CreditCardToken.php
Normal file
42
lib/PayPal/Api/CreditCardToken.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CreditCardToken extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for credit_card_id
|
||||||
|
* @param string $credit_card_id
|
||||||
|
*/
|
||||||
|
public function setCredit_card_id($credit_card_id) {
|
||||||
|
$this->credit_card_id = $credit_card_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for credit_card_id
|
||||||
|
*/
|
||||||
|
public function getCredit_card_id() {
|
||||||
|
return $this->credit_card_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payer_id
|
||||||
|
* @param string $payer_id
|
||||||
|
*/
|
||||||
|
public function setPayer_id($payer_id) {
|
||||||
|
$this->payer_id = $payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payer_id
|
||||||
|
*/
|
||||||
|
public function getPayer_id() {
|
||||||
|
return $this->payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
42
lib/PayPal/Api/FundingInstrument.php
Normal file
42
lib/PayPal/Api/FundingInstrument.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class FundingInstrument extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for credit_card
|
||||||
|
* @param PayPal\Api\CreditCard $credit_card
|
||||||
|
*/
|
||||||
|
public function setCredit_card($credit_card) {
|
||||||
|
$this->credit_card = $credit_card;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for credit_card
|
||||||
|
*/
|
||||||
|
public function getCredit_card() {
|
||||||
|
return $this->credit_card;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for credit_card_token
|
||||||
|
* @param PayPal\Api\CreditCardToken $credit_card_token
|
||||||
|
*/
|
||||||
|
public function setCredit_card_token($credit_card_token) {
|
||||||
|
$this->credit_card_token = $credit_card_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for credit_card_token
|
||||||
|
*/
|
||||||
|
public function getCredit_card_token() {
|
||||||
|
return $this->credit_card_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
87
lib/PayPal/Api/Item.php
Normal file
87
lib/PayPal/Api/Item.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Item extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for name
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function setName($name) {
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for name
|
||||||
|
*/
|
||||||
|
public function getName() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for sku
|
||||||
|
* @param string $sku
|
||||||
|
*/
|
||||||
|
public function setSku($sku) {
|
||||||
|
$this->sku = $sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for sku
|
||||||
|
*/
|
||||||
|
public function getSku() {
|
||||||
|
return $this->sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for price
|
||||||
|
* @param string $price
|
||||||
|
*/
|
||||||
|
public function setPrice($price) {
|
||||||
|
$this->price = $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for price
|
||||||
|
*/
|
||||||
|
public function getPrice() {
|
||||||
|
return $this->price;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for currency
|
||||||
|
* @param string $currency
|
||||||
|
*/
|
||||||
|
public function setCurrency($currency) {
|
||||||
|
$this->currency = $currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for currency
|
||||||
|
*/
|
||||||
|
public function getCurrency() {
|
||||||
|
return $this->currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for quantity
|
||||||
|
* @param string $quantity
|
||||||
|
*/
|
||||||
|
public function setQuantity($quantity) {
|
||||||
|
$this->quantity = $quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for quantity
|
||||||
|
*/
|
||||||
|
public function getQuantity() {
|
||||||
|
return $this->quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
42
lib/PayPal/Api/ItemList.php
Normal file
42
lib/PayPal/Api/ItemList.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ItemList extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for items
|
||||||
|
* @param PayPal\Api\Item $items
|
||||||
|
*/
|
||||||
|
public function setItems($items) {
|
||||||
|
$this->items = $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for items
|
||||||
|
*/
|
||||||
|
public function getItems() {
|
||||||
|
return $this->items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for shipping_address
|
||||||
|
* @param PayPal\Api\ShippingAddress $shipping_address
|
||||||
|
*/
|
||||||
|
public function setShipping_address($shipping_address) {
|
||||||
|
$this->shipping_address = $shipping_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for shipping_address
|
||||||
|
*/
|
||||||
|
public function getShipping_address() {
|
||||||
|
return $this->shipping_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
57
lib/PayPal/Api/Link.php
Normal file
57
lib/PayPal/Api/Link.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Link extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for href
|
||||||
|
* @param string $href
|
||||||
|
*/
|
||||||
|
public function setHref($href) {
|
||||||
|
$this->href = $href;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for href
|
||||||
|
*/
|
||||||
|
public function getHref() {
|
||||||
|
return $this->href;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for rel
|
||||||
|
* @param string $rel
|
||||||
|
*/
|
||||||
|
public function setRel($rel) {
|
||||||
|
$this->rel = $rel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for rel
|
||||||
|
*/
|
||||||
|
public function getRel() {
|
||||||
|
return $this->rel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for method
|
||||||
|
* @param string $method
|
||||||
|
*/
|
||||||
|
public function setMethod($method) {
|
||||||
|
$this->method = $method;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for method
|
||||||
|
*/
|
||||||
|
public function getMethod() {
|
||||||
|
return $this->method;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
57
lib/PayPal/Api/Payee.php
Normal file
57
lib/PayPal/Api/Payee.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Payee extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for merchant_id
|
||||||
|
* @param string $merchant_id
|
||||||
|
*/
|
||||||
|
public function setMerchant_id($merchant_id) {
|
||||||
|
$this->merchant_id = $merchant_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for merchant_id
|
||||||
|
*/
|
||||||
|
public function getMerchant_id() {
|
||||||
|
return $this->merchant_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for email
|
||||||
|
* @param string $email
|
||||||
|
*/
|
||||||
|
public function setEmail($email) {
|
||||||
|
$this->email = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for email
|
||||||
|
*/
|
||||||
|
public function getEmail() {
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for phone
|
||||||
|
* @param string $phone
|
||||||
|
*/
|
||||||
|
public function setPhone($phone) {
|
||||||
|
$this->phone = $phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for phone
|
||||||
|
*/
|
||||||
|
public function getPhone() {
|
||||||
|
return $this->phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
57
lib/PayPal/Api/Payer.php
Normal file
57
lib/PayPal/Api/Payer.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Payer extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payment_method
|
||||||
|
* @param string $payment_method
|
||||||
|
*/
|
||||||
|
public function setPayment_method($payment_method) {
|
||||||
|
$this->payment_method = $payment_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payment_method
|
||||||
|
*/
|
||||||
|
public function getPayment_method() {
|
||||||
|
return $this->payment_method;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payer_info
|
||||||
|
* @param PayPal\Api\PayerInfo $payer_info
|
||||||
|
*/
|
||||||
|
public function setPayer_info($payer_info) {
|
||||||
|
$this->payer_info = $payer_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payer_info
|
||||||
|
*/
|
||||||
|
public function getPayer_info() {
|
||||||
|
return $this->payer_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for funding_instruments
|
||||||
|
* @param PayPal\Api\FundingInstrument $funding_instruments
|
||||||
|
*/
|
||||||
|
public function setFunding_instruments($funding_instruments) {
|
||||||
|
$this->funding_instruments = $funding_instruments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for funding_instruments
|
||||||
|
*/
|
||||||
|
public function getFunding_instruments() {
|
||||||
|
return $this->funding_instruments;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
102
lib/PayPal/Api/PayerInfo.php
Normal file
102
lib/PayPal/Api/PayerInfo.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PayerInfo extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for email
|
||||||
|
* @param string $email
|
||||||
|
*/
|
||||||
|
public function setEmail($email) {
|
||||||
|
$this->email = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for email
|
||||||
|
*/
|
||||||
|
public function getEmail() {
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for first_name
|
||||||
|
* @param string $first_name
|
||||||
|
*/
|
||||||
|
public function setFirst_name($first_name) {
|
||||||
|
$this->first_name = $first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for first_name
|
||||||
|
*/
|
||||||
|
public function getFirst_name() {
|
||||||
|
return $this->first_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for last_name
|
||||||
|
* @param string $last_name
|
||||||
|
*/
|
||||||
|
public function setLast_name($last_name) {
|
||||||
|
$this->last_name = $last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for last_name
|
||||||
|
*/
|
||||||
|
public function getLast_name() {
|
||||||
|
return $this->last_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payer_id
|
||||||
|
* @param string $payer_id
|
||||||
|
*/
|
||||||
|
public function setPayer_id($payer_id) {
|
||||||
|
$this->payer_id = $payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payer_id
|
||||||
|
*/
|
||||||
|
public function getPayer_id() {
|
||||||
|
return $this->payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for shipping_address
|
||||||
|
* @param PayPal\Api\Address $shipping_address
|
||||||
|
*/
|
||||||
|
public function setShipping_address($shipping_address) {
|
||||||
|
$this->shipping_address = $shipping_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for shipping_address
|
||||||
|
*/
|
||||||
|
public function getShipping_address() {
|
||||||
|
return $this->shipping_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for phone
|
||||||
|
* @param string $phone
|
||||||
|
*/
|
||||||
|
public function setPhone($phone) {
|
||||||
|
$this->phone = $phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for phone
|
||||||
|
*/
|
||||||
|
public function getPhone() {
|
||||||
|
return $this->phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
244
lib/PayPal/Api/Payment.php
Normal file
244
lib/PayPal/Api/Payment.php
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
use PayPal\Rest\IResource;
|
||||||
|
use PayPal\Rest\Call;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Payment extends Resource implements IResource {
|
||||||
|
|
||||||
|
private static $credential;
|
||||||
|
|
||||||
|
public static function setCredential($credential) {
|
||||||
|
self::$credential = $credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for id
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for id
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for create_time
|
||||||
|
* @param string $create_time
|
||||||
|
*/
|
||||||
|
public function setCreate_time($create_time) {
|
||||||
|
$this->create_time = $create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for create_time
|
||||||
|
*/
|
||||||
|
public function getCreate_time() {
|
||||||
|
return $this->create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for update_time
|
||||||
|
* @param string $update_time
|
||||||
|
*/
|
||||||
|
public function setUpdate_time($update_time) {
|
||||||
|
$this->update_time = $update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for update_time
|
||||||
|
*/
|
||||||
|
public function getUpdate_time() {
|
||||||
|
return $this->update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for intent
|
||||||
|
* @param string $intent
|
||||||
|
*/
|
||||||
|
public function setIntent($intent) {
|
||||||
|
$this->intent = $intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for intent
|
||||||
|
*/
|
||||||
|
public function getIntent() {
|
||||||
|
return $this->intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payer
|
||||||
|
* @param PayPal\Api\Payer $payer
|
||||||
|
*/
|
||||||
|
public function setPayer($payer) {
|
||||||
|
$this->payer = $payer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payer
|
||||||
|
*/
|
||||||
|
public function getPayer() {
|
||||||
|
return $this->payer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for transactions
|
||||||
|
* @param PayPal\Api\Transaction $transactions
|
||||||
|
*/
|
||||||
|
public function setTransactions($transactions) {
|
||||||
|
$this->transactions = $transactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for transactions
|
||||||
|
*/
|
||||||
|
public function getTransactions() {
|
||||||
|
return $this->transactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for redirect_urls
|
||||||
|
* @param PayPal\Api\RedirectUrls $redirect_urls
|
||||||
|
*/
|
||||||
|
public function setRedirect_urls($redirect_urls) {
|
||||||
|
$this->redirect_urls = $redirect_urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for redirect_urls
|
||||||
|
*/
|
||||||
|
public function getRedirect_urls() {
|
||||||
|
return $this->redirect_urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for links
|
||||||
|
* @param PayPal\Api\Link $links
|
||||||
|
*/
|
||||||
|
public function setLinks($links) {
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for links
|
||||||
|
*/
|
||||||
|
public function getLinks() {
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/payment
|
||||||
|
* @method GET
|
||||||
|
* @param array $params
|
||||||
|
* array containing the query strings with the
|
||||||
|
* following values as keys:
|
||||||
|
* count,
|
||||||
|
* start_id,
|
||||||
|
* start_index,
|
||||||
|
* start_time,
|
||||||
|
* end_time,
|
||||||
|
* payee_id,
|
||||||
|
* sort_by,
|
||||||
|
* sort_order,
|
||||||
|
* All other keys in the map are ignored by the SDK
|
||||||
|
*/
|
||||||
|
public static function all($params) {
|
||||||
|
$payLoad = "";
|
||||||
|
$allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
|
||||||
|
|
||||||
|
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad, $apiContext);
|
||||||
|
$ret = new PaymentHistory();
|
||||||
|
$ret->fromJson($json);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/payment
|
||||||
|
* @method POST
|
||||||
|
|
||||||
|
* @param PayPal\Rest\ApiContext $apiContext optional
|
||||||
|
*/
|
||||||
|
public function create( $apiContext=null) {
|
||||||
|
$payLoad = $this->toJSON();
|
||||||
|
if($apiContext == null) {
|
||||||
|
$apiContext = new ApiContext(self::$credential);
|
||||||
|
}
|
||||||
|
$call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/payment", "POST", $payLoad, $apiContext);
|
||||||
|
$this->fromJson($json);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/payment/:payment-id
|
||||||
|
* @method GET
|
||||||
|
* @param string $paymentid
|
||||||
|
*/
|
||||||
|
public static function get( $paymentid) {
|
||||||
|
if (($paymentid == null) || (strlen($paymentid) <= 0)) {
|
||||||
|
throw new \InvalidArgumentException("paymentid cannot be null or empty");
|
||||||
|
}
|
||||||
|
$payLoad = "";
|
||||||
|
|
||||||
|
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/payment/$paymentid", "GET", $payLoad, $apiContext);
|
||||||
|
$ret = new Payment();
|
||||||
|
$ret->fromJson($json);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/payment/:payment-id/execute
|
||||||
|
* @method POST
|
||||||
|
* @param PaymentExecution $payment_execution
|
||||||
|
* @param PayPal\Rest\ApiContext $apiContext optional
|
||||||
|
*/
|
||||||
|
public function execute( $payment_execution, $apiContext=null) {
|
||||||
|
if ($payment_execution == null) {
|
||||||
|
throw new \InvalidArgumentException("payment_execution cannot be null");
|
||||||
|
}
|
||||||
|
if ($this->getId() == null) {
|
||||||
|
throw new \InvalidArgumentException("Id cannot be null");
|
||||||
|
}
|
||||||
|
$payLoad = $payment_execution->toJSON();
|
||||||
|
if($apiContext == null) {
|
||||||
|
$apiContext = new ApiContext(self::$credential);
|
||||||
|
}
|
||||||
|
$call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad, $apiContext);
|
||||||
|
$this->fromJson($json);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
42
lib/PayPal/Api/PaymentExecution.php
Normal file
42
lib/PayPal/Api/PaymentExecution.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PaymentExecution extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payer_id
|
||||||
|
* @param string $payer_id
|
||||||
|
*/
|
||||||
|
public function setPayer_id($payer_id) {
|
||||||
|
$this->payer_id = $payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payer_id
|
||||||
|
*/
|
||||||
|
public function getPayer_id() {
|
||||||
|
return $this->payer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for transactions
|
||||||
|
* @param PayPal\Api\Amount $transactions
|
||||||
|
*/
|
||||||
|
public function setTransactions($transactions) {
|
||||||
|
$this->transactions = $transactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for transactions
|
||||||
|
*/
|
||||||
|
public function getTransactions() {
|
||||||
|
return $this->transactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
57
lib/PayPal/Api/PaymentHistory.php
Normal file
57
lib/PayPal/Api/PaymentHistory.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PaymentHistory extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payments
|
||||||
|
* @param PayPal\Api\Payment $payments
|
||||||
|
*/
|
||||||
|
public function setPayments($payments) {
|
||||||
|
$this->payments = $payments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payments
|
||||||
|
*/
|
||||||
|
public function getPayments() {
|
||||||
|
return $this->payments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for count
|
||||||
|
* @param integer $count
|
||||||
|
*/
|
||||||
|
public function setCount($count) {
|
||||||
|
$this->count = $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for count
|
||||||
|
*/
|
||||||
|
public function getCount() {
|
||||||
|
return $this->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for next_id
|
||||||
|
* @param string $next_id
|
||||||
|
*/
|
||||||
|
public function setNext_id($next_id) {
|
||||||
|
$this->next_id = $next_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for next_id
|
||||||
|
*/
|
||||||
|
public function getNext_id() {
|
||||||
|
return $this->next_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
42
lib/PayPal/Api/RedirectUrls.php
Normal file
42
lib/PayPal/Api/RedirectUrls.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class RedirectUrls extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for return_url
|
||||||
|
* @param string $return_url
|
||||||
|
*/
|
||||||
|
public function setReturn_url($return_url) {
|
||||||
|
$this->return_url = $return_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for return_url
|
||||||
|
*/
|
||||||
|
public function getReturn_url() {
|
||||||
|
return $this->return_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for cancel_url
|
||||||
|
* @param string $cancel_url
|
||||||
|
*/
|
||||||
|
public function setCancel_url($cancel_url) {
|
||||||
|
$this->cancel_url = $cancel_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for cancel_url
|
||||||
|
*/
|
||||||
|
public function getCancel_url() {
|
||||||
|
return $this->cancel_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
191
lib/PayPal/Api/Refund.php
Normal file
191
lib/PayPal/Api/Refund.php
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
use PayPal\Rest\IResource;
|
||||||
|
use PayPal\Rest\Call;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Refund extends Resource implements IResource {
|
||||||
|
|
||||||
|
private static $credential;
|
||||||
|
|
||||||
|
public static function setCredential($credential) {
|
||||||
|
self::$credential = $credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for id
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for id
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for create_time
|
||||||
|
* @param string $create_time
|
||||||
|
*/
|
||||||
|
public function setCreate_time($create_time) {
|
||||||
|
$this->create_time = $create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for create_time
|
||||||
|
*/
|
||||||
|
public function getCreate_time() {
|
||||||
|
return $this->create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for update_time
|
||||||
|
* @param string $update_time
|
||||||
|
*/
|
||||||
|
public function setUpdate_time($update_time) {
|
||||||
|
$this->update_time = $update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for update_time
|
||||||
|
*/
|
||||||
|
public function getUpdate_time() {
|
||||||
|
return $this->update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for amount
|
||||||
|
* @param PayPal\Api\Amount $amount
|
||||||
|
*/
|
||||||
|
public function setAmount($amount) {
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for amount
|
||||||
|
*/
|
||||||
|
public function getAmount() {
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for sale_id
|
||||||
|
* @param string $sale_id
|
||||||
|
*/
|
||||||
|
public function setSale_id($sale_id) {
|
||||||
|
$this->sale_id = $sale_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for sale_id
|
||||||
|
*/
|
||||||
|
public function getSale_id() {
|
||||||
|
return $this->sale_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for capture_id
|
||||||
|
* @param string $capture_id
|
||||||
|
*/
|
||||||
|
public function setCapture_id($capture_id) {
|
||||||
|
$this->capture_id = $capture_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for capture_id
|
||||||
|
*/
|
||||||
|
public function getCapture_id() {
|
||||||
|
return $this->capture_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for parent_payment
|
||||||
|
* @param string $parent_payment
|
||||||
|
*/
|
||||||
|
public function setParent_payment($parent_payment) {
|
||||||
|
$this->parent_payment = $parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for parent_payment
|
||||||
|
*/
|
||||||
|
public function getParent_payment() {
|
||||||
|
return $this->parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for description
|
||||||
|
* @param string $description
|
||||||
|
*/
|
||||||
|
public function setDescription($description) {
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for description
|
||||||
|
*/
|
||||||
|
public function getDescription() {
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for links
|
||||||
|
* @param PayPal\Api\Link $links
|
||||||
|
*/
|
||||||
|
public function setLinks($links) {
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for links
|
||||||
|
*/
|
||||||
|
public function getLinks() {
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/refund/:refund-id
|
||||||
|
* @method GET
|
||||||
|
* @param string $refundid
|
||||||
|
*/
|
||||||
|
public static function get( $refundid) {
|
||||||
|
if (($refundid == null) || (strlen($refundid) <= 0)) {
|
||||||
|
throw new \InvalidArgumentException("refundid cannot be null or empty");
|
||||||
|
}
|
||||||
|
$payLoad = "";
|
||||||
|
|
||||||
|
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/refund/$refundid", "GET", $payLoad, $apiContext);
|
||||||
|
$ret = new Refund();
|
||||||
|
$ret->fromJson($json);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
13
lib/PayPal/Api/Resource.php
Normal file
13
lib/PayPal/Api/Resource.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
use PayPal\Common\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Resource extends Model {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
169
lib/PayPal/Api/Sale.php
Normal file
169
lib/PayPal/Api/Sale.php
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
use PayPal\Rest\IResource;
|
||||||
|
use PayPal\Rest\Call;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Sale extends Resource implements IResource {
|
||||||
|
|
||||||
|
private static $credential;
|
||||||
|
|
||||||
|
public static function setCredential($credential) {
|
||||||
|
self::$credential = $credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for id
|
||||||
|
* @param string $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for id
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for create_time
|
||||||
|
* @param string $create_time
|
||||||
|
*/
|
||||||
|
public function setCreate_time($create_time) {
|
||||||
|
$this->create_time = $create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for create_time
|
||||||
|
*/
|
||||||
|
public function getCreate_time() {
|
||||||
|
return $this->create_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for update_time
|
||||||
|
* @param string $update_time
|
||||||
|
*/
|
||||||
|
public function setUpdate_time($update_time) {
|
||||||
|
$this->update_time = $update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for update_time
|
||||||
|
*/
|
||||||
|
public function getUpdate_time() {
|
||||||
|
return $this->update_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for state
|
||||||
|
* @param string $state
|
||||||
|
*/
|
||||||
|
public function setState($state) {
|
||||||
|
$this->state = $state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for state
|
||||||
|
*/
|
||||||
|
public function getState() {
|
||||||
|
return $this->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for amount
|
||||||
|
* @param PayPal\Api\Amount $amount
|
||||||
|
*/
|
||||||
|
public function setAmount($amount) {
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for amount
|
||||||
|
*/
|
||||||
|
public function getAmount() {
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for parent_payment
|
||||||
|
* @param string $parent_payment
|
||||||
|
*/
|
||||||
|
public function setParent_payment($parent_payment) {
|
||||||
|
$this->parent_payment = $parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for parent_payment
|
||||||
|
*/
|
||||||
|
public function getParent_payment() {
|
||||||
|
return $this->parent_payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for links
|
||||||
|
* @param PayPal\Api\Link $links
|
||||||
|
*/
|
||||||
|
public function setLinks($links) {
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for links
|
||||||
|
*/
|
||||||
|
public function getLinks() {
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/sale/:sale-id
|
||||||
|
* @method GET
|
||||||
|
* @param string $saleid
|
||||||
|
*/
|
||||||
|
public static function get( $saleid) {
|
||||||
|
if (($saleid == null) || (strlen($saleid) <= 0)) {
|
||||||
|
throw new \InvalidArgumentException("saleid cannot be null or empty");
|
||||||
|
}
|
||||||
|
$payLoad = "";
|
||||||
|
|
||||||
|
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/sale/$saleid", "GET", $payLoad, $apiContext);
|
||||||
|
$ret = new Sale();
|
||||||
|
$ret->fromJson($json);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @path /v1/payments/sale/:sale-id/refund
|
||||||
|
* @method POST
|
||||||
|
* @param Refund $refund
|
||||||
|
* @param PayPal\Rest\ApiContext $apiContext optional
|
||||||
|
*/
|
||||||
|
public function refund( $refund, $apiContext=null) {
|
||||||
|
if ($refund == null) {
|
||||||
|
throw new \InvalidArgumentException("refund cannot be null");
|
||||||
|
}
|
||||||
|
if ($this->getId() == null) {
|
||||||
|
throw new \InvalidArgumentException("Id cannot be null");
|
||||||
|
}
|
||||||
|
$payLoad = $refund->toJSON();
|
||||||
|
if($apiContext == null) {
|
||||||
|
$apiContext = new ApiContext(self::$credential);
|
||||||
|
}
|
||||||
|
$call = new Call();
|
||||||
|
$json = $call->execute("/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad, $apiContext);
|
||||||
|
$this->fromJson($json);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
27
lib/PayPal/Api/ShippingAddress.php
Normal file
27
lib/PayPal/Api/ShippingAddress.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ShippingAddress extends Address {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for recipient_name
|
||||||
|
* @param string $recipient_name
|
||||||
|
*/
|
||||||
|
public function setRecipient_name($recipient_name) {
|
||||||
|
$this->recipient_name = $recipient_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for recipient_name
|
||||||
|
*/
|
||||||
|
public function getRecipient_name() {
|
||||||
|
return $this->recipient_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
72
lib/PayPal/Api/SubTransaction.php
Normal file
72
lib/PayPal/Api/SubTransaction.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SubTransaction extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for sale
|
||||||
|
* @param PayPal\Api\Sale $sale
|
||||||
|
*/
|
||||||
|
public function setSale($sale) {
|
||||||
|
$this->sale = $sale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for sale
|
||||||
|
*/
|
||||||
|
public function getSale() {
|
||||||
|
return $this->sale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for authorization
|
||||||
|
* @param PayPal\Api\Authorization $authorization
|
||||||
|
*/
|
||||||
|
public function setAuthorization($authorization) {
|
||||||
|
$this->authorization = $authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for authorization
|
||||||
|
*/
|
||||||
|
public function getAuthorization() {
|
||||||
|
return $this->authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for refund
|
||||||
|
* @param PayPal\Api\Refund $refund
|
||||||
|
*/
|
||||||
|
public function setRefund($refund) {
|
||||||
|
$this->refund = $refund;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for refund
|
||||||
|
*/
|
||||||
|
public function getRefund() {
|
||||||
|
return $this->refund;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for capture
|
||||||
|
* @param PayPal\Api\Capture $capture
|
||||||
|
*/
|
||||||
|
public function setCapture($capture) {
|
||||||
|
$this->capture = $capture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for capture
|
||||||
|
*/
|
||||||
|
public function getCapture() {
|
||||||
|
return $this->capture;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
87
lib/PayPal/Api/Transaction.php
Normal file
87
lib/PayPal/Api/Transaction.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Transaction extends Resource {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for amount
|
||||||
|
* @param PayPal\Api\Amount $amount
|
||||||
|
*/
|
||||||
|
public function setAmount($amount) {
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for amount
|
||||||
|
*/
|
||||||
|
public function getAmount() {
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for payee
|
||||||
|
* @param PayPal\Api\Payee $payee
|
||||||
|
*/
|
||||||
|
public function setPayee($payee) {
|
||||||
|
$this->payee = $payee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for payee
|
||||||
|
*/
|
||||||
|
public function getPayee() {
|
||||||
|
return $this->payee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for description
|
||||||
|
* @param string $description
|
||||||
|
*/
|
||||||
|
public function setDescription($description) {
|
||||||
|
$this->description = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for description
|
||||||
|
*/
|
||||||
|
public function getDescription() {
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for item_list
|
||||||
|
* @param PayPal\Api\ItemList $item_list
|
||||||
|
*/
|
||||||
|
public function setItem_list($item_list) {
|
||||||
|
$this->item_list = $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for item_list
|
||||||
|
*/
|
||||||
|
public function getItem_list() {
|
||||||
|
return $this->item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for related_resources
|
||||||
|
* @param PayPal\Api\SubTransaction $related_resources
|
||||||
|
*/
|
||||||
|
public function setRelated_resources($related_resources) {
|
||||||
|
$this->related_resources = $related_resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for related_resources
|
||||||
|
*/
|
||||||
|
public function getRelated_resources() {
|
||||||
|
return $this->related_resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
118
lib/PayPal/Auth/OAuthTokenCredential.php
Normal file
118
lib/PayPal/Auth/OAuthTokenCredential.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Oauth Token credential
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class OAuthTokenCredential {
|
||||||
|
|
||||||
|
private static $expiryBufferTime = 120;
|
||||||
|
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client ID as obtained from the developer portal
|
||||||
|
*/
|
||||||
|
private $clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client secret as obtained from the developer portal
|
||||||
|
*/
|
||||||
|
private $clientSecret;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generated Access Token
|
||||||
|
*/
|
||||||
|
private $accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seconds for with access token is valid
|
||||||
|
*/
|
||||||
|
private $tokenExpiresIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last time (in milliseconds) when access token was generated
|
||||||
|
*/
|
||||||
|
private $tokenCreateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $clientId client id obtained from the developer portal
|
||||||
|
* @param string $clientSecret client secret obtained from the developer portal
|
||||||
|
*/
|
||||||
|
public function __construct($clientId, $clientSecret) {
|
||||||
|
$this->clientId = $clientId;
|
||||||
|
$this->clientSecret = $clientSecret;
|
||||||
|
$this->logger = new \PPLoggingManager(__CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the accessToken
|
||||||
|
*/
|
||||||
|
public function getAccessToken() {
|
||||||
|
// Check if Access Token is not null and has not expired.
|
||||||
|
// The API returns expiry time as a relative time unit
|
||||||
|
// We use a buffer time when checking for token expiry to account
|
||||||
|
// for API call delays and any delay between the time the token is
|
||||||
|
// retrieved and subsequently used
|
||||||
|
if ($this->accessToken != null &&
|
||||||
|
(time() - $this->tokenCreateTime) > ($this->tokenExpiresIn - self::$expiryBufferTime)) {
|
||||||
|
$this->accessToken = null;
|
||||||
|
}
|
||||||
|
// If accessToken is Null, obtain a new token
|
||||||
|
if ($this->accessToken == null) {
|
||||||
|
$this->generateAccessToken();
|
||||||
|
}
|
||||||
|
return $this->accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a new access token
|
||||||
|
*/
|
||||||
|
private function generateAccessToken() {
|
||||||
|
return $this->generateOAuthToken(base64_encode($this->clientId . ":" . $this->clientSecret));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate OAuth type token from Base64Client ID
|
||||||
|
*/
|
||||||
|
private function generateOAuthToken($base64ClientID) {
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
"Authorization" => "Basic " . $base64ClientID,
|
||||||
|
"Accept" => "*/*"
|
||||||
|
);
|
||||||
|
$httpConfiguration = $this->getOAuthHttpConfiguration();
|
||||||
|
$httpConfiguration->setHeaders($headers);
|
||||||
|
|
||||||
|
$connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration);
|
||||||
|
$res = $connection->execute("grant_type=client_credentials");
|
||||||
|
$jsonResponse = json_decode($res, true);
|
||||||
|
if($jsonResponse == NULL ||
|
||||||
|
!isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) {
|
||||||
|
$this->accessToken = NULL;
|
||||||
|
$this->tokenExpiresIn = NULL;
|
||||||
|
$this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);
|
||||||
|
} else {
|
||||||
|
$this->accessToken = $jsonResponse["access_token"];
|
||||||
|
$this->tokenExpiresIn = $jsonResponse["expires_in"];
|
||||||
|
}
|
||||||
|
$this->tokenCreateTime = time();
|
||||||
|
return $this->accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get HttpConfiguration object for OAuth API
|
||||||
|
*/
|
||||||
|
private function getOAuthHttpConfiguration() {
|
||||||
|
$configMgr = \PPConfigManager::getInstance();
|
||||||
|
|
||||||
|
$baseEndpoint = ($configMgr->get("oauth.EndPoint") != '' && !is_array($configMgr->get("oauth.EndPoint"))) ?
|
||||||
|
$configMgr->get("oauth.EndPoint") : $configMgr->get("service.EndPoint");
|
||||||
|
$baseEndpoint = rtrim(trim($baseEndpoint), '/');
|
||||||
|
return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST");
|
||||||
|
}
|
||||||
|
}
|
||||||
19
lib/PayPal/Common/ArrayUtil.php
Normal file
19
lib/PayPal/Common/ArrayUtil.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Common;
|
||||||
|
|
||||||
|
class ArrayUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param array $arr
|
||||||
|
* @return true if $arr is an associative array
|
||||||
|
*/
|
||||||
|
public static function isAssocArray(array $arr) {
|
||||||
|
foreach($arr as $k => $v) {
|
||||||
|
if(is_int($k)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
88
lib/PayPal/Common/Model.php
Normal file
88
lib/PayPal/Common/Model.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Common;
|
||||||
|
|
||||||
|
use PayPal\Api\Payer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic Model class that all API domain classes extend
|
||||||
|
* Stores all member data in a hashmap that enables easy
|
||||||
|
* JSON encoding/decoding
|
||||||
|
*/
|
||||||
|
class Model {
|
||||||
|
|
||||||
|
private $_propMap = array();
|
||||||
|
|
||||||
|
public function __get($key) {
|
||||||
|
return $this->_propMap[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __set($key, $value) {
|
||||||
|
$this->_propMap[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __isset($key) {
|
||||||
|
return isset($this->_propMap[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __unset($key) {
|
||||||
|
unset($this->_propMap[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function _convertToArray($param) {
|
||||||
|
$ret = array();
|
||||||
|
foreach($param as $k => $v) {
|
||||||
|
if($v instanceof Model ) {
|
||||||
|
$ret[$k] = $v->toArray();
|
||||||
|
} else if (is_array($v)) {
|
||||||
|
$ret[$k] = $this->_convertToArray($v);
|
||||||
|
} else {
|
||||||
|
$ret[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromArray($arr) {
|
||||||
|
|
||||||
|
foreach($arr as $k => $v) {
|
||||||
|
if(is_array($v)) {
|
||||||
|
$clazz = ReflectionUtil::getPropertyClass(get_class($this), $k);
|
||||||
|
if(ArrayUtil::isAssocArray($v)) {
|
||||||
|
$o = new $clazz();
|
||||||
|
$o->fromArray($v);
|
||||||
|
$setterFunc = "set".ucfirst($k);
|
||||||
|
$this->$setterFunc($o);
|
||||||
|
} else {
|
||||||
|
$setterFunc = "set".ucfirst($k);
|
||||||
|
$arr = array();
|
||||||
|
foreach($v as $nk => $nv) {
|
||||||
|
if(is_array($nv)) {
|
||||||
|
$o = new $clazz();
|
||||||
|
$o->fromArray($nv);
|
||||||
|
$arr[$nk] = $o;
|
||||||
|
} else {
|
||||||
|
$arr[$nk] = $nv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->$setterFunc($arr); //TODO: Cleaning up any current values in this case. Should be doing this allways
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
$this->$k = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromJson($json) {
|
||||||
|
$this->fromArray(json_decode($json, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray() {
|
||||||
|
return $this->_convertToArray($this->_propMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJSON() {
|
||||||
|
return json_encode($this->toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
73
lib/PayPal/Common/ReflectionUtil.php
Normal file
73
lib/PayPal/Common/ReflectionUtil.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Common;
|
||||||
|
|
||||||
|
class ReflectionUtil {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|ReflectionMethod[]
|
||||||
|
*/
|
||||||
|
private static $propertiesRefl = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|string[]
|
||||||
|
*/
|
||||||
|
private static $propertiesType = array();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
* @param string $propertyName
|
||||||
|
*/
|
||||||
|
public static function getPropertyClass($class, $propertyName) {
|
||||||
|
|
||||||
|
if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['param'])) {
|
||||||
|
// if (substr($annotations['param'], -2) === '[]') {
|
||||||
|
// $param = substr($annotations['param'], 0, -2);
|
||||||
|
// }
|
||||||
|
$param = $annotations['param'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($param)) {
|
||||||
|
$anno = explode(' ', $param);
|
||||||
|
return $anno[0];
|
||||||
|
} else {
|
||||||
|
return 'string';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $class
|
||||||
|
* @param string $propertyName
|
||||||
|
* @throws RuntimeException
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function propertyAnnotations($class, $propertyName)
|
||||||
|
{
|
||||||
|
$class = is_object($class) ? get_class($class) : $class;
|
||||||
|
if (!class_exists('ReflectionProperty')) {
|
||||||
|
throw new RuntimeException("Property type of " . $class . "::{$propertyName} cannot be resolved");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($annotations =& self::$propertiesType[$class][$propertyName]) {
|
||||||
|
return $annotations;
|
||||||
|
}
|
||||||
|
|
||||||
|
$setterFunc = "set" . ucfirst($propertyName);
|
||||||
|
if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
|
||||||
|
$refl = new \ReflectionMethod($class, $setterFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: smarter regexp
|
||||||
|
if (!preg_match_all('~\@([^\s@\(]+)[\t ]*(?:\(?([^\n@]+)\)?)?~i', $refl->getDocComment(), $annots, PREG_PATTERN_ORDER)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
foreach ($annots[1] as $i => $annot) {
|
||||||
|
$annotations[strtolower($annot)] = empty($annots[2][$i]) ? TRUE : rtrim($annots[2][$i], " \t\n\r)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $annotations;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
lib/PayPal/Common/UserAgent.php
Normal file
44
lib/PayPal/Common/UserAgent.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Common;
|
||||||
|
|
||||||
|
define('SDK_NAME', 'REST-SDK-PHP');
|
||||||
|
define('SDK_VERSION', '0.5.0');
|
||||||
|
|
||||||
|
class UserAgent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the User-Agent header
|
||||||
|
* Add environment values and php version numbers
|
||||||
|
*/
|
||||||
|
public static function getValue() {
|
||||||
|
|
||||||
|
$featureList = array(
|
||||||
|
'Lang=PHP',
|
||||||
|
'V=' . PHP_VERSION,
|
||||||
|
'Bit=' . UserAgent::_getPHPBit(),
|
||||||
|
'OS=' . str_replace(' ' , '_', php_uname('s') . ' ' . php_uname('r')),
|
||||||
|
'Machine=' . php_uname('m')
|
||||||
|
);
|
||||||
|
if(defined('OPENSSL_VERSION_TEXT')) {
|
||||||
|
$opensslVersion = explode(' ', OPENSSL_VERSION_TEXT);
|
||||||
|
$featureList[] = 'Openssl='. $opensslVersion[1];
|
||||||
|
}
|
||||||
|
if(function_exists('curl_version')) {
|
||||||
|
$curlVersion = curl_version();
|
||||||
|
$featureList[] = 'curl=' . $curlVersion['version'];
|
||||||
|
}
|
||||||
|
return sprintf("PayPalSDK/%s %s (%s)", SDK_NAME, SDK_VERSION, implode(';', $featureList));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function _getPHPBit() {
|
||||||
|
switch(PHP_INT_SIZE) {
|
||||||
|
case 4:
|
||||||
|
return '32';
|
||||||
|
case 8:
|
||||||
|
return '64';
|
||||||
|
default:
|
||||||
|
return PHP_INT_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
74
lib/PayPal/Rest/ApiContext.php
Normal file
74
lib/PayPal/Rest/ApiContext.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Rest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Call level parameters such as
|
||||||
|
* request id, credentials etc
|
||||||
|
*/
|
||||||
|
class ApiContext {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth Credentials to use for this call
|
||||||
|
* @var PayPal/Api/OAuthTokenCredential
|
||||||
|
*/
|
||||||
|
private $credential;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique request id to be used for this call
|
||||||
|
* The user can either generate one as per application
|
||||||
|
* needs or let the SDK generate one
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $requestId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getCredential() {
|
||||||
|
return $this->credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getrequestId() {
|
||||||
|
if($this->requestId == null) {
|
||||||
|
$this->requestId = $this->generaterequestId();
|
||||||
|
}
|
||||||
|
return $this->requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param PayPal/Api/OAuthTokenCredential $credential
|
||||||
|
* @param string $requestId
|
||||||
|
*/
|
||||||
|
public function __construct($credential, $requestId=null) {
|
||||||
|
$this->credential = $credential;
|
||||||
|
$this->requestId = $requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a unique per request id that
|
||||||
|
* can be used to set the PayPal-Request-Id header
|
||||||
|
* that is used for idemptency
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function generateRequestId() {
|
||||||
|
|
||||||
|
static $pid = -1;
|
||||||
|
static $addr = -1;
|
||||||
|
|
||||||
|
if ($pid == -1) {
|
||||||
|
$pid = getmypid();
|
||||||
|
}
|
||||||
|
if ($addr == -1) {
|
||||||
|
if(array_key_exists('SERVER_ADDR', $_SERVER)) {
|
||||||
|
$addr = ip2long($_SERVER['SERVER_ADDR']);
|
||||||
|
} else {
|
||||||
|
$addr = php_uname('n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $addr . $pid . $_SERVER['REQUEST_TIME'] . mt_rand(0, 0xffff);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
lib/PayPal/Rest/Call.php
Normal file
59
lib/PayPal/Rest/Call.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Rest;
|
||||||
|
|
||||||
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
|
||||||
|
use PayPal\Common\UserAgent;
|
||||||
|
|
||||||
|
class Call {
|
||||||
|
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->logger = new \PPLoggingManager(__CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @param string $data
|
||||||
|
* @param PayPal/Rest/ApiContext $apiContext
|
||||||
|
* @param array $headers
|
||||||
|
*/
|
||||||
|
public function execute($path, $method, $data='', $apiContext, $headers=array()) {
|
||||||
|
$configMgr = \PPConfigManager::getInstance();
|
||||||
|
|
||||||
|
$credential = $apiContext->getCredential();
|
||||||
|
if($credential == NULL) {
|
||||||
|
// Try picking credentials from the config file
|
||||||
|
$credMgr = \PPCredentialManager::getInstance();
|
||||||
|
$credValues = $credMgr->getCredentialObject();
|
||||||
|
if(!is_array($credValues)) {
|
||||||
|
throw new \PPMissingCredentialException("Empty or invalid credentials passed");
|
||||||
|
}
|
||||||
|
$credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
|
||||||
|
}
|
||||||
|
if($credential == NULL || ! ($credential instanceof OAuthTokenCredential) ) {
|
||||||
|
throw new \PPInvalidCredentialException("Invalid credentials passed");
|
||||||
|
}
|
||||||
|
|
||||||
|
$resourceUrl = rtrim( trim($configMgr->get('service.EndPoint')), '/') . $path;
|
||||||
|
$config = new \PPHttpConfig($resourceUrl, $method);
|
||||||
|
$headers += array(
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'User-Agent' => UserAgent::getValue()
|
||||||
|
);
|
||||||
|
if(!is_null($credential) && $credential instanceof OAuthTokenCredential) {
|
||||||
|
$headers['Authorization'] = "Bearer " . $credential->getAccessToken();
|
||||||
|
}
|
||||||
|
if($method == 'POST' || $method == 'PUT') {
|
||||||
|
$headers['PayPal-Request-Id'] = $apiContext->getRequestId();
|
||||||
|
}
|
||||||
|
$config->setHeaders($headers);
|
||||||
|
$connection = new \PPHttpConnection($config);
|
||||||
|
$response = $connection->execute($data);
|
||||||
|
$this->logger->fine($response);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
lib/PayPal/Rest/IResource.php
Normal file
7
lib/PayPal/Rest/IResource.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Rest;
|
||||||
|
|
||||||
|
interface IResource {
|
||||||
|
|
||||||
|
}
|
||||||
29
phpunit.xml
Normal file
29
phpunit.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit bootstrap="./tests/bootstrap.php"
|
||||||
|
colors="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
syntaxCheck="false"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader">
|
||||||
|
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="All">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<logging>
|
||||||
|
<log type="junit" target="build/junit.xml" logIncompleteSkipped="false" />
|
||||||
|
</logging>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">./lib</directory>
|
||||||
|
<exclude>
|
||||||
|
</exclude>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
||||||
14
sample/README.md
Normal file
14
sample/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
Rest API Samples
|
||||||
|
===================
|
||||||
|
|
||||||
|
|
||||||
|
This sample project is a simple web app that you can explore to understand what the payment APIs can do for you. To try out the sample, run `composer update` from the samples folder and you are all set.
|
||||||
|
|
||||||
|
|
||||||
|
The sample comes pre-configured with a test account but in case you need to try them against your account, you must
|
||||||
|
|
||||||
|
* Obtain your client id and client secret from the developer portal
|
||||||
|
* Update the sdk_config.ini file with your new client id and secret.
|
||||||
|
|
||||||
|
|
||||||
|
If you are looking for a full fledged application that uses the new RESTful APIs, check out the Pizza store sample app at https://github.com/paypal/rest-api-sample-app-php
|
||||||
50
sample/bootstrap.php
Normal file
50
sample/bootstrap.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Sample bootstrap file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Include the composer autoloader
|
||||||
|
if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
|
||||||
|
echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
|
||||||
|
define("PP_CONFIG_PATH", __DIR__);
|
||||||
|
|
||||||
|
$configManager = \PPConfigManager::getInstance();
|
||||||
|
|
||||||
|
// $cred is used by samples that include this bootstrap file
|
||||||
|
// This piece of code simply demonstrates how you can
|
||||||
|
// dynamically pass in a client id/secret instead of using
|
||||||
|
// the config file. If you do not need a way to pass
|
||||||
|
// in credentials dynamically, you can skip the
|
||||||
|
// <Resource>::setCredential($cred) calls that
|
||||||
|
// you see in the samples.
|
||||||
|
$cred = new OAuthTokenCredential(
|
||||||
|
$configManager->get('acct1.ClientId'),
|
||||||
|
$configManager->get('acct1.ClientSecret'));
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### getBaseUrl function
|
||||||
|
* // utility function that returns base url for
|
||||||
|
* // determining return/cancel urls
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getBaseUrl() {
|
||||||
|
|
||||||
|
$protocol = 'http';
|
||||||
|
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) {
|
||||||
|
$protocol .= 's';
|
||||||
|
$protocol_port = $_SERVER['SERVER_PORT'];
|
||||||
|
} else {
|
||||||
|
$protocol_port = 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
|
$port = $_SERVER['SERVER_PORT'];
|
||||||
|
$request = $_SERVER['PHP_SELF'];
|
||||||
|
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
|
||||||
|
}
|
||||||
14
sample/composer.json
Normal file
14
sample/composer.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "paypal/rest-api-sdk-sample-php",
|
||||||
|
"description": "Samples using PayPal's REST API SDK for PHP",
|
||||||
|
"homepage": "https://github.com/paypal/rest-api-sdk-php",
|
||||||
|
"config": {
|
||||||
|
"require-all": true
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0",
|
||||||
|
"ext-curl": "*",
|
||||||
|
"ext-json": "*",
|
||||||
|
"paypal/rest-api-sdk-php" : "0.5.*"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
sample/images/edt-format-source-button.png
Normal file
BIN
sample/images/edt-format-source-button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 173 B |
BIN
sample/images/play_button.png
Normal file
BIN
sample/images/play_button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
94
sample/index.html
Normal file
94
sample/index.html
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
<title>PayPal REST API Samples</title>
|
||||||
|
<style>
|
||||||
|
.imagelink {
|
||||||
|
padding: 5px 0px 5px 28px;
|
||||||
|
}
|
||||||
|
.execute {
|
||||||
|
background: url('images/play_button.png') no-repeat left top;
|
||||||
|
}
|
||||||
|
.source {
|
||||||
|
background: url('images/edt-format-source-button.png') no-repeat left top;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<center>
|
||||||
|
<h3>PayPal REST API Samples</h3>
|
||||||
|
</center>
|
||||||
|
<br /><br />
|
||||||
|
<table cellspacing="5" width="85%">
|
||||||
|
<tbody>
|
||||||
|
<tr valign="top">
|
||||||
|
<td>Payment with a credit card</td>
|
||||||
|
<td></td>
|
||||||
|
<td width="30%" ><a href="payments/CreatePayment.php" class="execute imagelink">Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td width="30%"><a href="source/CreatePayment.html" class="source imagelink">Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Payment with a PayPal Account</td>
|
||||||
|
|
||||||
|
<td></td>
|
||||||
|
<td><a href="payments/CreatePaymentUsingPayPal.php" class="execute imagelink">Execute</a></td>
|
||||||
|
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/CreatePaymentUsingPayPal.html" class="source imagelink">Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Get Payment Details</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="payments/GetPayment.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/GetPayment.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Get Payment History</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="payments/ListPayments.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/ListPayments.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Get Sale Details</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="sale/GetSale.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/GetSale.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Refund a Payment</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="sale/RefundSale.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/RefundSale.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Save a credit card</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="vault/CreateCreditCard.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/CreateCreditCard.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Retrieve saved credit card</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="vault/GetCreditCard.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/GetCreditCard.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Payment with saved credit card</td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="payments/CreatePaymentUsingSavedCard.php" class="execute imagelink" >Execute</a></td>
|
||||||
|
<td></td>
|
||||||
|
<td><a href="source/CreatePaymentUsingSavedCard.html" class="source imagelink" >Source</a></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
111
sample/payments/CreatePayment.php
Normal file
111
sample/payments/CreatePayment.php
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # CreatePaymentSample
|
||||||
|
// This sample code demonstrate how you can process
|
||||||
|
// a payment with a credit card.
|
||||||
|
// API used: /v1/payments/payment
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Api\CreditCard;
|
||||||
|
use PayPal\Api\Payer;
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
use PayPal\Api\FundingInstrument;
|
||||||
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
// ### Address
|
||||||
|
// Base Address object used as shipping or billing
|
||||||
|
// address in a payment. [Optional]
|
||||||
|
$addr = new Address();
|
||||||
|
$addr->setLine1("3909 Witmer Road");
|
||||||
|
$addr->setLine2("Niagara Falls");
|
||||||
|
$addr->setCity("Niagara Falls");
|
||||||
|
$addr->setState("NY");
|
||||||
|
$addr->setPostal_code("14305");
|
||||||
|
$addr->setCountry_code("US");
|
||||||
|
$addr->setPhone("716-298-1822");
|
||||||
|
|
||||||
|
// ### CreditCard
|
||||||
|
// A resource representing a credit card that can be
|
||||||
|
// used to fund a payment.
|
||||||
|
$card = new CreditCard();
|
||||||
|
$card->setType("visa");
|
||||||
|
$card->setNumber("4417119669820331");
|
||||||
|
$card->setExpire_month("11");
|
||||||
|
$card->setExpire_year("2019");
|
||||||
|
$card->setCvv2("012");
|
||||||
|
$card->setFirst_name("Joe");
|
||||||
|
$card->setLast_name("Shopper");
|
||||||
|
$card->setBilling_address($addr);
|
||||||
|
|
||||||
|
// ### FundingInstrument
|
||||||
|
// A resource representing a Payer's funding instrument.
|
||||||
|
// Use a Payer ID (A unique identifier of the payer generated
|
||||||
|
// and provided by the facilitator. This is required when
|
||||||
|
// creating or using a tokenized funding instrument)
|
||||||
|
// and the `CreditCardDetails`
|
||||||
|
$fi = new FundingInstrument();
|
||||||
|
$fi->setCredit_card($card);
|
||||||
|
|
||||||
|
// ### Payer
|
||||||
|
// A resource representing a Payer that funds a payment
|
||||||
|
// Use the List of `FundingInstrument` and the Payment Method
|
||||||
|
// as 'credit_card'
|
||||||
|
$payer = new Payer();
|
||||||
|
$payer->setPayment_method("credit_card");
|
||||||
|
$payer->setFunding_instruments(array($fi));
|
||||||
|
|
||||||
|
// ### Amount
|
||||||
|
// Let's you specify a payment amount.
|
||||||
|
$amount = new Amount();
|
||||||
|
$amount->setCurrency("USD");
|
||||||
|
$amount->setTotal("1.00");
|
||||||
|
|
||||||
|
// ### Transaction
|
||||||
|
// A transaction defines the contract of a
|
||||||
|
// payment - what is the payment for and who
|
||||||
|
// is fulfilling it. Transaction is created with
|
||||||
|
// a `Payee` and `Amount` types
|
||||||
|
$transaction = new Transaction();
|
||||||
|
$transaction->setAmount($amount);
|
||||||
|
$transaction->setDescription("This is the payment description.");
|
||||||
|
|
||||||
|
// ### Payment
|
||||||
|
// A Payment Resource; create one using
|
||||||
|
// the above types and intent as 'sale'
|
||||||
|
$payment = new Payment();
|
||||||
|
$payment->setIntent("sale");
|
||||||
|
$payment->setPayer($payer);
|
||||||
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
|
// ### Api Context
|
||||||
|
// Pass in a `ApiContext` object to authenticate
|
||||||
|
// the call and to send a unique request id
|
||||||
|
// (that ensures idempotency). The SDK generates
|
||||||
|
// a request id if you do not pass one explicitly.
|
||||||
|
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||||
|
|
||||||
|
// ### Create Payment
|
||||||
|
// Create a payment by posting to the APIService
|
||||||
|
// using a valid ApiContext
|
||||||
|
// The return object contains the status;
|
||||||
|
try {
|
||||||
|
$payment->create($apiContext);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
Created payment:
|
||||||
|
<?php echo $payment->getId();?>
|
||||||
|
</div>
|
||||||
|
<pre><?php var_dump($payment->toArray());?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
93
sample/payments/CreatePaymentUsingPayPal.php
Normal file
93
sample/payments/CreatePaymentUsingPayPal.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # Create Payment using PayPal as payment method
|
||||||
|
// This sample code demonstrates how you can process a
|
||||||
|
// PayPal Account based Payment.
|
||||||
|
// API used: /v1/payments/payment
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Api\Payer;
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
use PayPal\Api\FundingInstrument;
|
||||||
|
use PayPal\Api\RedirectUrls;
|
||||||
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// ### Payer
|
||||||
|
// A resource representing a Payer that funds a payment
|
||||||
|
// Use the List of `FundingInstrument` and the Payment Method
|
||||||
|
// as 'credit_card'
|
||||||
|
$payer = new Payer();
|
||||||
|
$payer->setPayment_method("paypal");
|
||||||
|
|
||||||
|
// ### Amount
|
||||||
|
// Let's you specify a payment amount.
|
||||||
|
$amount = new Amount();
|
||||||
|
$amount->setCurrency("USD");
|
||||||
|
$amount->setTotal("1.00");
|
||||||
|
|
||||||
|
// ### Transaction
|
||||||
|
// A transaction defines the contract of a
|
||||||
|
// payment - what is the payment for and who
|
||||||
|
// is fulfilling it. Transaction is created with
|
||||||
|
// a `Payee` and `Amount` types
|
||||||
|
$transaction = new Transaction();
|
||||||
|
$transaction->setAmount($amount);
|
||||||
|
$transaction->setDescription("This is the payment description.");
|
||||||
|
|
||||||
|
// ### Redirect urls
|
||||||
|
// Set the urls that the buyer must be redirected to after
|
||||||
|
// payment approval/ cancellation.
|
||||||
|
$baseUrl = getBaseUrl();
|
||||||
|
$redirectUrls = new RedirectUrls();
|
||||||
|
$redirectUrls->setReturn_url("$baseUrl/ExecutePayment.php?success=true");
|
||||||
|
$redirectUrls->setCancel_url("$baseUrl/ExecutePayment.php?success=false");
|
||||||
|
|
||||||
|
// ### Payment
|
||||||
|
// A Payment Resource; create one using
|
||||||
|
// the above types and intent as 'sale'
|
||||||
|
$payment = new Payment();
|
||||||
|
$payment->setIntent("sale");
|
||||||
|
$payment->setPayer($payer);
|
||||||
|
$payment->setRedirect_urls($redirectUrls);
|
||||||
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
|
// ### Api Context
|
||||||
|
// Pass in a `ApiContext` object to authenticate
|
||||||
|
// the call and to send a unique request id
|
||||||
|
// (that ensures idempotency). The SDK generates
|
||||||
|
// a request id if you do not pass one explicitly.
|
||||||
|
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||||
|
|
||||||
|
// ### Create Payment
|
||||||
|
// Create a payment by posting to the APIService
|
||||||
|
// using a valid apiContext
|
||||||
|
// The return object contains the status and the
|
||||||
|
// url to which the buyer must be redirected to
|
||||||
|
// for payment approval
|
||||||
|
try {
|
||||||
|
$payment->create($apiContext);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ### Redirect buyer to paypal
|
||||||
|
// Retrieve buyer approval url from the `payment` object.
|
||||||
|
foreach($payment->getLinks() as $link) {
|
||||||
|
if($link->getRel() == 'approval_url') {
|
||||||
|
$redirectUrl = $link->getHref();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// It is not really a great idea to store the payment id
|
||||||
|
// in the session. In a real world app, please store the
|
||||||
|
// payment id in a database.
|
||||||
|
$_SESSION['paymentId'] = $payment->getId();
|
||||||
|
if(isset($redirectUrl)) {
|
||||||
|
header("Location: $redirectUrl");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
96
sample/payments/CreatePaymentUsingSavedCard.php
Normal file
96
sample/payments/CreatePaymentUsingSavedCard.php
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # Create payment using a saved credit card
|
||||||
|
// This sample code demonstrates how you can process a
|
||||||
|
// Payment using a previously saved credit card.
|
||||||
|
// API used: /v1/payments/payment
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Api\CreditCard;
|
||||||
|
use PayPal\Api\CreditCardToken;
|
||||||
|
use PayPal\Api\Payer;
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
use PayPal\Api\FundingInstrument;
|
||||||
|
use PayPal\Api\RedirectUrls;
|
||||||
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
// ### Credit card token
|
||||||
|
// Saved credit card id from a previous call to
|
||||||
|
// CreateCreditCard.php
|
||||||
|
$creditCardId = 'CARD-5BT058015C739554AKE2GCEI';
|
||||||
|
$creditCardToken = new CreditCardToken();
|
||||||
|
$creditCardToken->setCredit_card_id($creditCardId);
|
||||||
|
|
||||||
|
// ### FundingInstrument
|
||||||
|
// A resource representing a Payer's funding instrument.
|
||||||
|
// Use a Payer ID (A unique identifier of the payer generated
|
||||||
|
// and provided by the facilitator. This is required when
|
||||||
|
// creating or using a tokenized funding instrument)
|
||||||
|
// and the `CreditCardDetails`
|
||||||
|
$fi = new FundingInstrument();
|
||||||
|
$fi->setCredit_card_token($creditCardToken);
|
||||||
|
|
||||||
|
// ### Payer
|
||||||
|
// A resource representing a Payer that funds a payment
|
||||||
|
// Use the List of `FundingInstrument` and the Payment Method
|
||||||
|
// as 'credit_card'
|
||||||
|
$payer = new Payer();
|
||||||
|
$payer->setPayment_method("credit_card");
|
||||||
|
$payer->setFunding_instruments(array($fi));
|
||||||
|
|
||||||
|
// ### Amount
|
||||||
|
// Let's you specify a payment amount.
|
||||||
|
$amount = new Amount();
|
||||||
|
$amount->setCurrency("USD");
|
||||||
|
$amount->setTotal("1.00");
|
||||||
|
|
||||||
|
// ### Transaction
|
||||||
|
// A transaction defines the contract of a
|
||||||
|
// payment - what is the payment for and who
|
||||||
|
// is fulfilling it. Transaction is created with
|
||||||
|
// a `Payee` and `Amount` types
|
||||||
|
$transaction = new Transaction();
|
||||||
|
$transaction->setAmount($amount);
|
||||||
|
$transaction->setDescription("This is the payment description.");
|
||||||
|
|
||||||
|
// ### Payment
|
||||||
|
// A Payment Resource; create one using
|
||||||
|
// the above types and intent as 'sale'
|
||||||
|
$payment = new Payment();
|
||||||
|
$payment->setIntent("sale");
|
||||||
|
$payment->setPayer($payer);
|
||||||
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
|
// ### Api Context
|
||||||
|
// Pass in a `ApiContext` object to authenticate
|
||||||
|
// the call and to send a unique request id
|
||||||
|
// (that ensures idempotency). The SDK generates
|
||||||
|
// a request id if you do not pass one explicitly.
|
||||||
|
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||||
|
|
||||||
|
// ###Create Payment
|
||||||
|
// Create a payment by posting to the APIService
|
||||||
|
// using a valid apiContext
|
||||||
|
// The return object contains the status;
|
||||||
|
try {
|
||||||
|
$payment->create($apiContext);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
Created payment:
|
||||||
|
<?php echo $payment->getId();?>
|
||||||
|
</div>
|
||||||
|
<pre><?php var_dump($payment->toArray());?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
47
sample/payments/ExecutePayment.php
Normal file
47
sample/payments/ExecutePayment.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
// #Execute Payment Sample
|
||||||
|
// This sample shows how you can complete
|
||||||
|
// a payment that has been approved by
|
||||||
|
// the buyer by logging into paypal site.
|
||||||
|
// You can optionally update transaction
|
||||||
|
// information by passing in one or more transactions.
|
||||||
|
// API used: POST '/v1/payments/payment/<payment-id>/execute'.
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\ExecutePayment;
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
use PayPal\Api\PaymentExecution;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if(isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||||
|
// ### Api Context
|
||||||
|
// Pass in a `ApiContext` object to authenticate
|
||||||
|
// the call and to send a unique request id
|
||||||
|
// (that ensures idempotency). The SDK generates
|
||||||
|
// a request id if you do not pass one explicitly.
|
||||||
|
$apiContext = new ApiContext($cred);
|
||||||
|
|
||||||
|
// Get the payment Object by passing paymentId
|
||||||
|
// payment id was previously stored in session in
|
||||||
|
// CreatePaymentUsingPayPal.php
|
||||||
|
$paymentId = $_SESSION['paymentId'];
|
||||||
|
$payment = Payment::get($paymentId);
|
||||||
|
|
||||||
|
// PaymentExecution object includes information necessary
|
||||||
|
// to execute a PayPal account payment.
|
||||||
|
// The payer_id is added to the request query parameters
|
||||||
|
// when the user is redirected from paypal back to your site
|
||||||
|
$execution = new PaymentExecution();
|
||||||
|
$execution->setPayer_id($_GET['PayerID']);
|
||||||
|
|
||||||
|
//Execute the payment
|
||||||
|
$payment->execute($execution, $apiContext);
|
||||||
|
|
||||||
|
echo "<html><body><pre>";
|
||||||
|
var_dump($payment->toArray());
|
||||||
|
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
echo "User cancelled payment.";
|
||||||
|
}
|
||||||
39
sample/payments/GetPayment.php
Normal file
39
sample/payments/GetPayment.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
// # GetPaymentSample
|
||||||
|
// This sample code demonstrate how you can
|
||||||
|
// retrieve a list of all Payment resources
|
||||||
|
// you've created using the Payments API.
|
||||||
|
// Note various query parameters that you can
|
||||||
|
// use to filter, and paginate through the
|
||||||
|
// payments list.
|
||||||
|
// API used: GET /v1/payments/payments
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
|
||||||
|
$paymentId = "PAY-0XL713371A312273YKE2GCNI";
|
||||||
|
|
||||||
|
// ### Authentication
|
||||||
|
// Pass in a `OAuthTokenCredential` object
|
||||||
|
// explicilty to authenticate the call.
|
||||||
|
Payment::setCredential($cred);
|
||||||
|
// ### Retrieve payment
|
||||||
|
// Retrieve the payment object by calling the
|
||||||
|
// static `get` method
|
||||||
|
// on the Payment class by passing a valid
|
||||||
|
// Payment ID
|
||||||
|
try {
|
||||||
|
$payment = Payment::get($paymentId);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
|
||||||
|
<pre><?php var_dump($payment->toArray());?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
42
sample/payments/ListPayments.php
Normal file
42
sample/payments/ListPayments.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// #GetPaymentList
|
||||||
|
// This sample code demonstrate how you can
|
||||||
|
// retrieve a list of all Payment resources
|
||||||
|
// you've created using the Payments API.
|
||||||
|
// Note various query parameters that you can
|
||||||
|
// use to filter, and paginate through the
|
||||||
|
// payments list.
|
||||||
|
// API used: GET /v1/payments/payments
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
|
||||||
|
// ### Authentication
|
||||||
|
// Pass in a `OAuthTokenCredential` object
|
||||||
|
// explicilty to authenticate the call.
|
||||||
|
// If you skip this step, the client id/secret
|
||||||
|
// set in the config file will be used.
|
||||||
|
Payment::setCredential($cred);
|
||||||
|
|
||||||
|
// ### Retrieve payment
|
||||||
|
// Retrieve the PaymentHistory object by calling the
|
||||||
|
// static `get` method on the Payment class,
|
||||||
|
// and pass a Map object that contains
|
||||||
|
// query parameters for paginations and filtering.
|
||||||
|
// Refer the method doc for valid values for keys
|
||||||
|
try {
|
||||||
|
$payments = Payment::all(array('count' => 10, 'start_index' => 5));
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>Got <?php echo $payments->getCount(); ?> matching payments </div>
|
||||||
|
<pre><?php var_dump($payments->toArray());?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
35
sample/sale/GetSale.php
Normal file
35
sample/sale/GetSale.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # Get Sale sample
|
||||||
|
// This sample code demonstrates how you can retrieve
|
||||||
|
// details of completed Sale Transaction.
|
||||||
|
// API used: /v1/payments/sale/{sale-id}
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Sale;
|
||||||
|
|
||||||
|
$saleId = '3RM92092UW5126232';
|
||||||
|
// ### Authentication
|
||||||
|
// Pass in a `OAuthTokenCredential` object
|
||||||
|
// explicilty to authenticate the call.
|
||||||
|
// If you skip this step, the client id/secret
|
||||||
|
// set in the config file will be used.
|
||||||
|
Sale::setCredential($cred);
|
||||||
|
try {
|
||||||
|
// ### Retrieve the sale object
|
||||||
|
// Pass the ID of the sale
|
||||||
|
// transaction from your payment resource.
|
||||||
|
$sale = Sale::get($saleId);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>Retrieving sale id: <?php echo $saleId;?></div>
|
||||||
|
<pre><?php var_dump($sale);?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
55
sample/sale/RefundSale.php
Normal file
55
sample/sale/RefundSale.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # Sale Refund Sample
|
||||||
|
// This sample code demonstrate how you can
|
||||||
|
// process a refund on a sale transaction created
|
||||||
|
// using the Payments API.
|
||||||
|
// API used: /v1/payments/sale/{sale-id}/refund
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Api\Refund;
|
||||||
|
use PayPal\Api\Sale;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
// ### Refund
|
||||||
|
// Create a refund object indicating
|
||||||
|
// refund amount
|
||||||
|
$amt = new Amount();
|
||||||
|
$amt->setCurrency('USD');
|
||||||
|
$amt->setTotal('0.01');
|
||||||
|
|
||||||
|
$refund = new Refund();
|
||||||
|
$refund->setAmount($amt);
|
||||||
|
|
||||||
|
$saleId = '3RM92092UW5126232';
|
||||||
|
|
||||||
|
// ###Sale
|
||||||
|
// A sale transaction.
|
||||||
|
// Create a Sale object with the
|
||||||
|
// given sale transaction id.
|
||||||
|
$sale = new Sale();
|
||||||
|
$sale->setId($saleId);
|
||||||
|
|
||||||
|
// ### Api Context
|
||||||
|
// Pass in a `ApiContext` object to authenticate
|
||||||
|
// the call and to send a unique request id
|
||||||
|
// (that ensures idempotency). The SDK generates
|
||||||
|
// a request id if you do not pass one explicitly.
|
||||||
|
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||||
|
try {
|
||||||
|
// Refund the sale
|
||||||
|
$sale->refund($refund, $apiContext);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>Refunding sale id: <?php echo $saleId;?></div>
|
||||||
|
<pre><?php var_dump($sale);?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
35
sample/sdk_config.ini
Normal file
35
sample/sdk_config.ini
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
;Account credentials from developer portal
|
||||||
|
[Account]
|
||||||
|
acct1.ClientId = EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
||||||
|
acct1.ClientSecret = EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
||||||
|
|
||||||
|
|
||||||
|
;Connection Information
|
||||||
|
[Http]
|
||||||
|
http.ConnectionTimeOut = 30
|
||||||
|
http.Retry = 1
|
||||||
|
;http.Proxy=http://[username:password]@hostname[:port][/path]
|
||||||
|
|
||||||
|
|
||||||
|
;Service Configuration
|
||||||
|
[Service]
|
||||||
|
service.EndPoint="https://api.sandbox.paypal.com"
|
||||||
|
; Uncomment this line for integrating with the live endpoint
|
||||||
|
; service.EndPoint="https://api.paypal.com"
|
||||||
|
|
||||||
|
|
||||||
|
;Logging Information
|
||||||
|
[Log]
|
||||||
|
|
||||||
|
log.LogEnabled=true
|
||||||
|
|
||||||
|
# When using a relative path, the log file is created
|
||||||
|
# relative to the .php file that is the entry point
|
||||||
|
# for this request. You can also provide an absolute
|
||||||
|
# path here
|
||||||
|
log.FileName=../PayPal.log
|
||||||
|
|
||||||
|
# Logging level can be one of FINE, INFO, WARN or ERROR
|
||||||
|
# Logging is most verbose in the 'FINE' level and
|
||||||
|
# decreases as you proceed towards ERROR
|
||||||
|
log.LogLevel=FINE
|
||||||
48
sample/source/CreateCreditCard.html
Normal file
48
sample/source/CreateCreditCard.html
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>CreateCreditCard</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="CreateCreditCard"><meta name="groc-project-path" content="CreateCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="create-credit-card-sample">Create Credit Card Sample</h1>
|
||||||
|
|
||||||
|
<p>Using the 'vault' API, you can store a
|
||||||
|
Credit Card securely on PayPal. You can
|
||||||
|
use a saved Credit Card to process
|
||||||
|
a payment in the future.
|
||||||
|
The following code demonstrates how
|
||||||
|
can save a Credit Card on PayPal using
|
||||||
|
the Vault API.
|
||||||
|
API used: POST /v1/vault/credit-card</p></div></div><div class="code"><div class="wrapper"><span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||||
|
|
||||||
|
<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\CreditCard</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Address</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="creditcard">CreditCard</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a credit card that can be
|
||||||
|
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setType</span><span class="p">(</span><span class="s2">"visa"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setNumber</span><span class="p">(</span><span class="s2">"4417119669820331"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">"11"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">"2019"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">"012"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">"Joe"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||||
|
the call and to send a unique request id
|
||||||
|
(that ensures idempotency). The SDK generates
|
||||||
|
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="save-card">Save card</h3>
|
||||||
|
|
||||||
|
<p>Creates the credit card as a resource
|
||||||
|
in the PayPal vault. The response contains
|
||||||
|
an 'id' that you can use to refer to it
|
||||||
|
in the future payments.</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">create</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="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>Saved a new credit card with id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$card</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span><span class="cp">?></span><span class="x"></div></span>
|
||||||
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></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></body></html>
|
||||||
90
sample/source/CreatePayment.html
Normal file
90
sample/source/CreatePayment.html
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>CreatePayment</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="CreatePayment"><meta name="groc-project-path" content="CreatePayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="createpaymentsample">CreatePaymentSample</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrate how you can process
|
||||||
|
a payment with a credit card.
|
||||||
|
API used: /v1/payments/payment</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\Address</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\Api\CreditCard</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</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="address">Address</h3>
|
||||||
|
|
||||||
|
<p>Base Address object used as shipping or billing
|
||||||
|
address in a payment. [Optional]</p></div></div><div class="code"><div class="wrapper"><span class="nv">$addr</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Address</span><span class="p">();</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setLine1</span><span class="p">(</span><span class="s2">"3909 Witmer Road"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setLine2</span><span class="p">(</span><span class="s2">"Niagara Falls"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setCity</span><span class="p">(</span><span class="s2">"Niagara Falls"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setState</span><span class="p">(</span><span class="s2">"NY"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setPostal_code</span><span class="p">(</span><span class="s2">"14305"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setCountry_code</span><span class="p">(</span><span class="s2">"US"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$addr</span><span class="o">-></span><span class="na">setPhone</span><span class="p">(</span><span class="s2">"716-298-1822"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a credit card that can be
|
||||||
|
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setType</span><span class="p">(</span><span class="s2">"visa"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setNumber</span><span class="p">(</span><span class="s2">"4417119669820331"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">"11"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">"2019"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">"012"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">"Joe"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setBilling_address</span><span class="p">(</span><span class="nv">$addr</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a Payer's funding instrument.
|
||||||
|
Use a Payer ID (A unique identifier of the payer generated
|
||||||
|
and provided by the facilitator. This is required when
|
||||||
|
creating or using a tokenized funding instrument)
|
||||||
|
and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span>
|
||||||
|
<span class="nv">$fi</span><span class="o">-></span><span class="na">setCredit_card</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a Payer that funds a payment
|
||||||
|
Use the List of <code>FundingInstrument</code> and the Payment Method
|
||||||
|
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
|
||||||
|
<span class="nv">$payer</span><span class="o">-></span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">"credit_card"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payer</span><span class="o">-></span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||||
|
|
||||||
|
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><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></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||||
|
|
||||||
|
<p>A transaction defines the contract of a
|
||||||
|
payment - what is the payment for and who
|
||||||
|
is fulfilling it. Transaction is created with
|
||||||
|
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
|
||||||
|
<span class="nv">$transaction</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="nv">$transaction</span><span class="o">-></span><span class="na">setDescription</span><span class="p">(</span><span class="s2">"This is the payment description."</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||||
|
|
||||||
|
<p>A Payment Resource; create one using
|
||||||
|
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||||
|
the call and to send a unique request id
|
||||||
|
(that ensures idempotency). The SDK generates
|
||||||
|
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||||
|
|
||||||
|
<p>Create a payment by posting to the APIService
|
||||||
|
using a valid ApiContext
|
||||||
|
The return object contains the status;</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</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="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="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></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"> Created payment:</span>
|
||||||
|
<span class="x"> </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$payment</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="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></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></body></html>
|
||||||
72
sample/source/CreatePaymentUsingPayPal.html
Normal file
72
sample/source/CreatePaymentUsingPayPal.html
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>CreatePaymentUsingPayPal</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="CreatePaymentUsingPayPal"><meta name="groc-project-path" content="CreatePaymentUsingPayPal.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="create-payment-using-paypal-as-payment-method">Create Payment using PayPal as payment method</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrates how you can process a
|
||||||
|
PayPal Account based Payment.
|
||||||
|
API used: /v1/payments/payment</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\Address</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\Api\Payer</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\RedirectUrls</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||||
|
<span class="nb">session_start</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="payer">Payer</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a Payer that funds a payment
|
||||||
|
Use the List of <code>FundingInstrument</code> and the Payment Method
|
||||||
|
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
|
||||||
|
<span class="nv">$payer</span><span class="o">-></span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">"paypal"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||||
|
|
||||||
|
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><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></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||||
|
|
||||||
|
<p>A transaction defines the contract of a
|
||||||
|
payment - what is the payment for and who
|
||||||
|
is fulfilling it. Transaction is created with
|
||||||
|
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
|
||||||
|
<span class="nv">$transaction</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="nv">$transaction</span><span class="o">-></span><span class="na">setDescription</span><span class="p">(</span><span class="s2">"This is the payment description."</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
|
||||||
|
|
||||||
|
<p>Set the urls that the buyer must be redirected to after
|
||||||
|
payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$baseUrl</span> <span class="o">=</span> <span class="nx">getBaseUrl</span><span class="p">();</span>
|
||||||
|
<span class="nv">$redirectUrls</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">RedirectUrls</span><span class="p">();</span>
|
||||||
|
<span class="nv">$redirectUrls</span><span class="o">-></span><span class="na">setReturn_url</span><span class="p">(</span><span class="s2">"</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=true"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$redirectUrls</span><span class="o">-></span><span class="na">setCancel_url</span><span class="p">(</span><span class="s2">"</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=false"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||||
|
|
||||||
|
<p>A Payment Resource; create one using
|
||||||
|
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setRedirect_urls</span><span class="p">(</span><span class="nv">$redirectUrls</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||||
|
the call and to send a unique request id
|
||||||
|
(that ensures idempotency). The SDK generates
|
||||||
|
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||||
|
|
||||||
|
<p>Create a payment by posting to the APIService
|
||||||
|
using a valid apiContext
|
||||||
|
The return object contains the status and the
|
||||||
|
url to which the buyer must be redirected to
|
||||||
|
for payment approval</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</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="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></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="redirect-buyer-to-paypal">Redirect buyer to paypal</h3>
|
||||||
|
|
||||||
|
<p>Retrieve buyer approval url from the <code>payment</code> object.</p></div></div><div class="code"><div class="wrapper"><span class="k">foreach</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">getLinks</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$link</span><span class="p">)</span> <span class="p">{</span>
|
||||||
|
<span class="k">if</span><span class="p">(</span><span class="nv">$link</span><span class="o">-></span><span class="na">getRel</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'approval_url'</span><span class="p">)</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$redirectUrl</span> <span class="o">=</span> <span class="nv">$link</span><span class="o">-></span><span class="na">getHref</span><span class="p">();</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow">¶</a></div><div class="wrapper"><p>It is not really a great idea to store the payment id
|
||||||
|
in the session. In a real world app, please store the
|
||||||
|
payment id in a database.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$payment</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span>
|
||||||
|
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$redirectUrl</span><span class="p">))</span> <span class="p">{</span>
|
||||||
|
<span class="nx">header</span><span class="p">(</span><span class="s2">"Location: </span><span class="si">$redirectUrl</span><span class="s2">"</span><span class="p">);</span>
|
||||||
|
<span class="k">exit</span><span class="p">;</span>
|
||||||
|
<span class="p">}</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></body></html>
|
||||||
77
sample/source/CreatePaymentUsingSavedCard.html
Normal file
77
sample/source/CreatePaymentUsingSavedCard.html
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>CreatePaymentUsingSavedCard</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="CreatePaymentUsingSavedCard"><meta name="groc-project-path" content="CreatePaymentUsingSavedCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="create-payment-using-a-saved-credit-card">Create payment using a saved credit card</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrates how you can process a
|
||||||
|
Payment using a previously saved credit card.
|
||||||
|
API used: /v1/payments/payment</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\Address</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\Api\CreditCard</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCardToken</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\RedirectUrls</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Auth\OAuthTokenCredential</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</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="credit-card-token">Credit card token</h3>
|
||||||
|
|
||||||
|
<p>Saved credit card id from a previous call to
|
||||||
|
CreateCreditCard.php</p></div></div><div class="code"><div class="wrapper"><span class="nv">$creditCardId</span> <span class="o">=</span> <span class="s1">'CARD-5BT058015C739554AKE2GCEI'</span><span class="p">;</span>
|
||||||
|
<span class="nv">$creditCardToken</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCardToken</span><span class="p">();</span>
|
||||||
|
<span class="nv">$creditCardToken</span><span class="o">-></span><span class="na">setCredit_card_id</span><span class="p">(</span><span class="nv">$creditCardId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a Payer's funding instrument.
|
||||||
|
Use a Payer ID (A unique identifier of the payer generated
|
||||||
|
and provided by the facilitator. This is required when
|
||||||
|
creating or using a tokenized funding instrument)
|
||||||
|
and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span>
|
||||||
|
<span class="nv">$fi</span><span class="o">-></span><span class="na">setCredit_card_token</span><span class="p">(</span><span class="nv">$creditCardToken</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||||
|
|
||||||
|
<p>A resource representing a Payer that funds a payment
|
||||||
|
Use the List of <code>FundingInstrument</code> and the Payment Method
|
||||||
|
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
|
||||||
|
<span class="nv">$payer</span><span class="o">-></span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">"credit_card"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payer</span><span class="o">-></span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||||
|
|
||||||
|
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><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></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||||
|
|
||||||
|
<p>A transaction defines the contract of a
|
||||||
|
payment - what is the payment for and who
|
||||||
|
is fulfilling it. Transaction is created with
|
||||||
|
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
|
||||||
|
<span class="nv">$transaction</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="nv">$transaction</span><span class="o">-></span><span class="na">setDescription</span><span class="p">(</span><span class="s2">"This is the payment description."</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||||
|
|
||||||
|
<p>A Payment Resource; create one using
|
||||||
|
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||||
|
the call and to send a unique request id
|
||||||
|
(that ensures idempotency). The SDK generates
|
||||||
|
a request id if you do not pass one explicitly.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||||
|
|
||||||
|
<p>Create a payment by posting to the APIService
|
||||||
|
using a valid apiContext
|
||||||
|
The return object contains the status;</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</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="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"> Created payment:</span>
|
||||||
|
<span class="x"> </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$payment</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="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></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></body></html>
|
||||||
40
sample/source/ExecutePayment.html
Normal file
40
sample/source/ExecutePayment.html
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>ExecutePayment</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="ExecutePayment"><meta name="groc-project-path" content="ExecutePayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="execute-payment-sample">Execute Payment Sample</h1>
|
||||||
|
|
||||||
|
<p>This sample shows how you can complete
|
||||||
|
a payment that has been approved by
|
||||||
|
the buyer by logging into paypal site.
|
||||||
|
You can optionally update transaction
|
||||||
|
information by passing in one or more transactions.
|
||||||
|
API used: POST '/v1/payments/payment/<payment-id>/execute'.</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\ExecutePayment</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\PaymentExecution</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||||
|
<span class="nb">session_start</span><span class="p">();</span>
|
||||||
|
|
||||||
|
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">])</span> <span class="o">&&</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'true'</span><span class="p">)</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="api-context">Api Context</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||||
|
the call and to send a unique request id
|
||||||
|
(that ensures idempotency). The SDK generates
|
||||||
|
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"> <span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||||
|
</div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||||
|
payment id was previously stored in session in
|
||||||
|
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$paymentId</span> <span class="o">=</span> <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">];</span>
|
||||||
|
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">);</span>
|
||||||
|
</div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||||
|
to execute a PayPal account payment.
|
||||||
|
The payer_id is added to the request query parameters
|
||||||
|
when the user is redirected from paypal back to your site</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$execution</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PaymentExecution</span><span class="p">();</span>
|
||||||
|
<span class="nv">$execution</span><span class="o">-></span><span class="na">setPayer_id</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'PayerID'</span><span class="p">]);</span>
|
||||||
|
|
||||||
|
<span class="c1">//Execute the payment</span>
|
||||||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">execute</span><span class="p">(</span><span class="nv">$execution</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||||
|
|
||||||
|
<span class="k">echo</span> <span class="s2">"<html><body><pre>"</span><span class="p">;</span>
|
||||||
|
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span>
|
||||||
|
<span class="k">echo</span> <span class="s2">"</pre><a href='../index.html'>Back</a></body></html>"</span><span class="p">;</span>
|
||||||
|
|
||||||
|
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||||||
|
<span class="k">echo</span> <span class="s2">"User cancelled payment."</span><span class="p">;</span>
|
||||||
|
<span class="p">}</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></body></html>
|
||||||
31
sample/source/GetCreditCard.html
Normal file
31
sample/source/GetCreditCard.html
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>GetCreditCard</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="GetCreditCard"><meta name="groc-project-path" content="GetCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="get-credit-card-sample">Get Credit Card Sample</h1>
|
||||||
|
|
||||||
|
<p>The CreditCard resource allows you to
|
||||||
|
retrieve previously saved CreditCards,
|
||||||
|
by sending a GET request to the URI
|
||||||
|
'/v1/vault/credit-card'
|
||||||
|
The following code takes you through
|
||||||
|
the process of retrieving a saved CreditCard</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\CreditCard</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"><p>The cardId can be obtained from a previous save credit
|
||||||
|
card operation. Use $card->getId()</p></div></div><div class="code"><div class="wrapper"><span class="nv">$cardId</span> <span class="o">=</span> <span class="s2">"CARD-5BT058015C739554AKE2GCEI"</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||||
|
explicilty to authenticate the call.
|
||||||
|
If you skip this step, the client id/secret
|
||||||
|
set in the config file will be used.</p></div></div><div class="code"><div class="wrapper"><span class="nx">CreditCard</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||||
|
<span class="c1">/// ### Retrieve card</span>
|
||||||
|
<span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$card</span> <span class="o">=</span> <span class="nx">CreditCard</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$cardId</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="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>Retrieving credit card: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$cardId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||||
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></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></body></html>
|
||||||
34
sample/source/GetPayment.html
Normal file
34
sample/source/GetPayment.html
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>GetPayment</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="GetPayment"><meta name="groc-project-path" content="GetPayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="getpaymentsample">GetPaymentSample</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrate how you can
|
||||||
|
retrieve a list of all Payment resources
|
||||||
|
you've created using the Payments API.
|
||||||
|
Note various query parameters that you can
|
||||||
|
use to filter, and paginate through the
|
||||||
|
payments list.
|
||||||
|
API used: GET /v1/payments/payments</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\Payment</span><span class="p">;</span>
|
||||||
|
|
||||||
|
<span class="nv">$paymentId</span> <span class="o">=</span> <span class="s2">"PAY-0XL713371A312273YKE2GCNI"</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="authentication">Authentication</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||||
|
explicilty to authenticate the call. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||||
|
|
||||||
|
<p>Retrieve the payment object by calling the
|
||||||
|
static <code>get</code> method
|
||||||
|
on the Payment class by passing a valid
|
||||||
|
Payment ID</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</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="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>Retrieving Payment ID: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$paymentId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||||
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></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></body></html>
|
||||||
30
sample/source/GetSale.html
Normal file
30
sample/source/GetSale.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>GetSale</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="GetSale"><meta name="groc-project-path" content="GetSale.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="get-sale-sample">Get Sale sample</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrates how you can retrieve
|
||||||
|
details of completed Sale Transaction.
|
||||||
|
API used: /v1/payments/sale/{sale-id}</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\Sale</span><span class="p">;</span>
|
||||||
|
|
||||||
|
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">'3RM92092UW5126232'</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="authentication">Authentication</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||||
|
explicilty to authenticate the call.
|
||||||
|
If you skip this step, the client id/secret
|
||||||
|
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Sale</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||||
|
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
|
||||||
|
|
||||||
|
<p>Pass the ID of the sale
|
||||||
|
transaction from your payment resource.</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span> <span class="o">=</span> <span class="nx">Sale</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$saleId</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="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>Retrieving sale id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||||
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?></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></body></html>
|
||||||
35
sample/source/ListPayments.html
Normal file
35
sample/source/ListPayments.html
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>ListPayments</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="ListPayments"><meta name="groc-project-path" content="ListPayments.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="getpaymentlist">GetPaymentList</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrate how you can
|
||||||
|
retrieve a list of all Payment resources
|
||||||
|
you've created using the Payments API.
|
||||||
|
Note various query parameters that you can
|
||||||
|
use to filter, and paginate through the
|
||||||
|
payments list.
|
||||||
|
API used: GET /v1/payments/payments</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\Payment</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="authentication">Authentication</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||||
|
explicilty to authenticate the call.
|
||||||
|
If you skip this step, the client id/secret
|
||||||
|
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||||
|
|
||||||
|
<p>Retrieve the PaymentHistory object by calling the
|
||||||
|
static <code>get</code> method on the Payment class,
|
||||||
|
and pass a Map object that contains
|
||||||
|
query parameters for paginations and filtering.
|
||||||
|
Refer the method doc for valid values for keys</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||||
|
<span class="nv">$payments</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">all</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'count'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'start_index'</span> <span class="o">=></span> <span class="mi">5</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="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>Got </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$payments</span><span class="o">-></span><span class="na">getCount</span><span class="p">();</span> <span class="cp">?></span><span class="x"> matching payments </div></span>
|
||||||
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payments</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></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></body></html>
|
||||||
44
sample/source/RefundSale.html
Normal file
44
sample/source/RefundSale.html
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html><html lang="en"><head><title>RefundSale</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="RefundSale"><meta name="groc-project-path" content="RefundSale.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><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"><h1 id="sale-refund-sample">Sale Refund Sample</h1>
|
||||||
|
|
||||||
|
<p>This sample code demonstrate how you can
|
||||||
|
process a refund on a sale transaction created
|
||||||
|
using the Payments API.
|
||||||
|
API used: /v1/payments/sale/{sale-id}/refund</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\Amount</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Refund</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Sale</span><span class="p">;</span>
|
||||||
|
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</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="refund">Refund</h3>
|
||||||
|
|
||||||
|
<p>Create a refund object indicating
|
||||||
|
refund amount</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amt</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
|
||||||
|
<span class="nv">$amt</span><span class="o">-></span><span class="na">setCurrency</span><span class="p">(</span><span class="s1">'USD'</span><span class="p">);</span>
|
||||||
|
<span class="nv">$amt</span><span class="o">-></span><span class="na">setTotal</span><span class="p">(</span><span class="s1">'0.01'</span><span class="p">);</span>
|
||||||
|
|
||||||
|
<span class="nv">$refund</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Refund</span><span class="p">();</span>
|
||||||
|
<span class="nv">$refund</span><span class="o">-></span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amt</span><span class="p">);</span>
|
||||||
|
|
||||||
|
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">'3RM92092UW5126232'</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="sale">Sale</h3>
|
||||||
|
|
||||||
|
<p>A sale transaction.
|
||||||
|
Create a Sale object with the
|
||||||
|
given sale transaction id.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$sale</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Sale</span><span class="p">();</span>
|
||||||
|
<span class="nv">$sale</span><span class="o">-></span><span class="na">setId</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||||
|
|
||||||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||||
|
the call and to send a unique request id
|
||||||
|
(that ensures idempotency). The SDK generates
|
||||||
|
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span>
|
||||||
|
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><p>Refund the sale</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span><span class="o">-></span><span class="na">refund</span><span class="p">(</span><span class="nv">$refund</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="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>Refunding sale id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||||
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?></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></body></html>
|
||||||
459
sample/source/assets/behavior.js
Normal file
459
sample/source/assets/behavior.js
Normal file
File diff suppressed because one or more lines are too long
93
sample/source/assets/docs.js
Normal file
93
sample/source/assets/docs.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* @depend jquery.nicescroll.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
var j_window = $(window),
|
||||||
|
j_flybar = $('#flybar');
|
||||||
|
j_sidebar = $('.sidebar_popout'),
|
||||||
|
j_content = $('#document');
|
||||||
|
|
||||||
|
var docs = {
|
||||||
|
init: function() {
|
||||||
|
this.sidebar_popout();
|
||||||
|
this.url_rewrite();
|
||||||
|
},
|
||||||
|
|
||||||
|
sidebar_popout: function() {
|
||||||
|
$('#sidebar_button').on('click', function() {
|
||||||
|
var sidebar_hidden_class = 'sidebar_hidden',
|
||||||
|
animation_speed = 200;
|
||||||
|
|
||||||
|
if ( !j_sidebar.hasClass(sidebar_hidden_class) ) {
|
||||||
|
j_sidebar.stop()
|
||||||
|
.animate({
|
||||||
|
marginLeft: -270
|
||||||
|
}, animation_speed)
|
||||||
|
.addClass(sidebar_hidden_class);
|
||||||
|
j_content.stop()
|
||||||
|
.animate({
|
||||||
|
paddingLeft: 18
|
||||||
|
}, animation_speed);
|
||||||
|
j_flybar.stop()
|
||||||
|
.animate({
|
||||||
|
marginLeft: -282
|
||||||
|
}, animation_speed);
|
||||||
|
$(this).stop()
|
||||||
|
.animate({
|
||||||
|
marginLeft: -270
|
||||||
|
}, animation_speed);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
j_sidebar.stop()
|
||||||
|
.animate({
|
||||||
|
marginLeft: 0
|
||||||
|
}, animation_speed)
|
||||||
|
.removeClass(sidebar_hidden_class);
|
||||||
|
j_content.stop()
|
||||||
|
.animate({
|
||||||
|
paddingLeft: 300
|
||||||
|
}, animation_speed);
|
||||||
|
j_flybar.stop()
|
||||||
|
.animate({
|
||||||
|
marginLeft: 0
|
||||||
|
}, animation_speed);
|
||||||
|
$(this).stop()
|
||||||
|
.animate({
|
||||||
|
marginLeft: 0
|
||||||
|
}, animation_speed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
url_rewrite: function() {
|
||||||
|
$('.sidebar .menu a').each(function() {
|
||||||
|
var j_this = $(this),
|
||||||
|
href = j_this.attr('href'),
|
||||||
|
url = new RegExp(window.location.protocol + '//' + window.location.host + window.location.pathname);
|
||||||
|
|
||||||
|
if (url.test(href)) {
|
||||||
|
href = href.replace(url, '#') // Replace domain and path
|
||||||
|
.replace(/\//g, '-') // Replace '/' with '-'
|
||||||
|
.replace(/-$/, ''); // Remove last '-'
|
||||||
|
|
||||||
|
j_this.attr('href', encodeURI(href));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
docs.init();
|
||||||
|
|
||||||
|
/* Enable Nice Scroll on docs sidebar */
|
||||||
|
// j_sidebar_docs.niceScroll({
|
||||||
|
// zindex: 1,
|
||||||
|
// cursorcolor: '#bbb',
|
||||||
|
// cursorwidth: '7px',
|
||||||
|
// cursorborder: '0',
|
||||||
|
// cursorborderradius: '10px',
|
||||||
|
// autohidemode: false,
|
||||||
|
// railoffset: { left: 15 }
|
||||||
|
// });
|
||||||
|
|
||||||
|
});
|
||||||
4
sample/source/assets/jquery.min.js
vendored
Normal file
4
sample/source/assets/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
sample/source/assets/sideNavOut.png
Normal file
BIN
sample/source/assets/sideNavOut.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 289 B |
BIN
sample/source/assets/sideNavOver.png
Normal file
BIN
sample/source/assets/sideNavOver.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 300 B |
1
sample/source/assets/style.css
Normal file
1
sample/source/assets/style.css
Normal file
File diff suppressed because one or more lines are too long
57
sample/vault/CreateCreditCard.php
Normal file
57
sample/vault/CreateCreditCard.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # Create Credit Card Sample
|
||||||
|
// Using the 'vault' API, you can store a
|
||||||
|
// Credit Card securely on PayPal. You can
|
||||||
|
// use a saved Credit Card to process
|
||||||
|
// a payment in the future.
|
||||||
|
// The following code demonstrates how
|
||||||
|
// can save a Credit Card on PayPal using
|
||||||
|
// the Vault API.
|
||||||
|
// API used: POST /v1/vault/credit-card
|
||||||
|
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\CreditCard;
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
|
||||||
|
// ### CreditCard
|
||||||
|
// A resource representing a credit card that can be
|
||||||
|
// used to fund a payment.
|
||||||
|
$card = new CreditCard();
|
||||||
|
$card->setType("visa");
|
||||||
|
$card->setNumber("4417119669820331");
|
||||||
|
$card->setExpire_month("11");
|
||||||
|
$card->setExpire_year("2019");
|
||||||
|
$card->setCvv2("012");
|
||||||
|
$card->setFirst_name("Joe");
|
||||||
|
$card->setLast_name("Shopper");
|
||||||
|
|
||||||
|
// ### Api Context
|
||||||
|
// Pass in a `ApiContext` object to authenticate
|
||||||
|
// the call and to send a unique request id
|
||||||
|
// (that ensures idempotency). The SDK generates
|
||||||
|
// a request id if you do not pass one explicitly.
|
||||||
|
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||||
|
|
||||||
|
// ### Save card
|
||||||
|
// Creates the credit card as a resource
|
||||||
|
// in the PayPal vault. The response contains
|
||||||
|
// an 'id' that you can use to refer to it
|
||||||
|
// in the future payments.
|
||||||
|
try {
|
||||||
|
$card->create();
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>Saved a new credit card with id: <?php echo $card->getId();?></div>
|
||||||
|
<pre><?php var_dump($card);?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
38
sample/vault/GetCreditCard.php
Normal file
38
sample/vault/GetCreditCard.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// # Get Credit Card Sample
|
||||||
|
// The CreditCard resource allows you to
|
||||||
|
// retrieve previously saved CreditCards,
|
||||||
|
// by sending a GET request to the URI
|
||||||
|
// '/v1/vault/credit-card'
|
||||||
|
// The following code takes you through
|
||||||
|
// the process of retrieving a saved CreditCard
|
||||||
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\CreditCard;
|
||||||
|
|
||||||
|
// The cardId can be obtained from a previous save credit
|
||||||
|
// card operation. Use $card->getId()
|
||||||
|
$cardId = "CARD-5BT058015C739554AKE2GCEI";
|
||||||
|
|
||||||
|
// ### Authentication
|
||||||
|
// Pass in a `OAuthTokenCredential` object
|
||||||
|
// explicilty to authenticate the call.
|
||||||
|
// If you skip this step, the client id/secret
|
||||||
|
// set in the config file will be used.
|
||||||
|
CreditCard::setCredential($cred);
|
||||||
|
/// ### Retrieve card
|
||||||
|
try {
|
||||||
|
$card = CreditCard::get($cardId);
|
||||||
|
} catch (\PPConnectionException $ex) {
|
||||||
|
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||||
|
var_dump($ex->getData());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div>Retrieving credit card: <?php echo $cardId;?></div>
|
||||||
|
<pre><?php var_dump($card);?></pre>
|
||||||
|
<a href='../index.html'>Back</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
56
tests/PayPal/Test/Api/AddressTest.php
Normal file
56
tests/PayPal/Test/Api/AddressTest.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class AddressTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $address;
|
||||||
|
|
||||||
|
public static $line1 = "3909 Witmer Road";
|
||||||
|
public static $line2 = "Niagara Falls";
|
||||||
|
public static $city = "Niagara Falls";
|
||||||
|
public static $state = "NY";
|
||||||
|
public static $postalCode = "14305";
|
||||||
|
public static $countryCode = "US";
|
||||||
|
public static $phone = "716-298-1822";
|
||||||
|
public static $type = "Billing";
|
||||||
|
|
||||||
|
public static function createAddress() {
|
||||||
|
$addr = new Address();
|
||||||
|
$addr->setLine1(self::$line1);
|
||||||
|
$addr->setLine2(self::$line2);
|
||||||
|
$addr->setCity(self::$city);
|
||||||
|
$addr->setState(self::$state);
|
||||||
|
$addr->setPostal_code(self::$postalCode);
|
||||||
|
$addr->setCountry_code(self::$countryCode);
|
||||||
|
$addr->setPhone(self::$phone);
|
||||||
|
$addr->setType(self::$type);
|
||||||
|
return $addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->address = self::createAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$line1, $this->address->getLine1());
|
||||||
|
$this->assertEquals(self::$line2, $this->address->getLine2());
|
||||||
|
$this->assertEquals(self::$city, $this->address->getCity());
|
||||||
|
$this->assertEquals(self::$state, $this->address->getState());
|
||||||
|
$this->assertEquals(self::$postalCode, $this->address->getPostal_code());
|
||||||
|
$this->assertEquals(self::$countryCode, $this->address->getCountry_code());
|
||||||
|
$this->assertEquals(self::$phone, $this->address->getPhone());
|
||||||
|
$this->assertEquals(self::$type, $this->address->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$a1 = $this->address;
|
||||||
|
|
||||||
|
$a2 = new Address();
|
||||||
|
$a2->fromJson($a1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($a1, $a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
tests/PayPal/Test/Api/AmountDetailsTest.php
Normal file
45
tests/PayPal/Test/Api/AmountDetailsTest.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\AmountDetails;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class AmountDetailsTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $amountDetails;
|
||||||
|
|
||||||
|
public static $subtotal = "2.00";
|
||||||
|
public static $tax = "1.12";
|
||||||
|
public static $shipping = "3.15";
|
||||||
|
public static $fee = "4.99";
|
||||||
|
|
||||||
|
public static function createAmountDetails() {
|
||||||
|
$amountDetails = new AmountDetails();
|
||||||
|
$amountDetails->setSubtotal(self::$subtotal);
|
||||||
|
$amountDetails->setTax(self::$tax);
|
||||||
|
$amountDetails->setShipping(self::$shipping);
|
||||||
|
$amountDetails->setFee(self::$fee);
|
||||||
|
|
||||||
|
return $amountDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->amountDetails = self::createAmountDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetters() {
|
||||||
|
$this->assertEquals(self::$subtotal, $this->amountDetails->getSubtotal());
|
||||||
|
$this->assertEquals(self::$tax, $this->amountDetails->getTax());
|
||||||
|
$this->assertEquals(self::$shipping, $this->amountDetails->getShipping());
|
||||||
|
$this->assertEquals(self::$fee, $this->amountDetails->getFee());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$a1 = $this->amountDetails;
|
||||||
|
|
||||||
|
$a2 = new AmountDetails();
|
||||||
|
$a2->fromJson($a1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($a1, $a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
tests/PayPal/Test/Api/AmountTest.php
Normal file
45
tests/PayPal/Test/Api/AmountTest.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class AmountTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $amounts;
|
||||||
|
|
||||||
|
public static $currency = "USD";
|
||||||
|
public static $total = "1.12";
|
||||||
|
|
||||||
|
public static function createAmount() {
|
||||||
|
$amount = new Amount();
|
||||||
|
$amount->setCurrency(self::$currency);
|
||||||
|
$amount->setTotal(self::$total);
|
||||||
|
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->amounts['partial'] = self::createAmount();
|
||||||
|
|
||||||
|
$amount = self::createAmount();
|
||||||
|
$amount->setDetails(AmountDetailsTest::createAmountDetails());
|
||||||
|
$this->amounts['full'] = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$currency, $this->amounts['partial']->getCurrency());
|
||||||
|
$this->assertEquals(self::$total, $this->amounts['partial']->getTotal());
|
||||||
|
$this->assertEquals(AmountDetailsTest::$fee, $this->amounts['full']->getDetails()->getFee());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$a1 = $this->amounts['partial'];
|
||||||
|
|
||||||
|
$a2 = new Amount();
|
||||||
|
$a2->fromJson($a1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($a1, $a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
tests/PayPal/Test/Api/AuthorizationTest.php
Normal file
69
tests/PayPal/Test/Api/AuthorizationTest.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Api\Authorization;
|
||||||
|
use PayPal\Api\Link;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $authorizations = array();
|
||||||
|
|
||||||
|
public static $create_time = "2013-02-28T00:00:00Z";
|
||||||
|
public static $id = "AUTH-123";
|
||||||
|
public static $state = "Created";
|
||||||
|
public static $parent_payment = "PAY-12345";
|
||||||
|
|
||||||
|
public static $currency = "USD";
|
||||||
|
public static $total = "1.12";
|
||||||
|
|
||||||
|
public static $href = "USD";
|
||||||
|
public static $rel = "1.12";
|
||||||
|
public static $method = "1.12";
|
||||||
|
|
||||||
|
public static function createAuthorization() {
|
||||||
|
$authorization = new Authorization();
|
||||||
|
$authorization->setCreate_time(self::$create_time);
|
||||||
|
$authorization->setId(self::$id);
|
||||||
|
$authorization->setState(self::$state);
|
||||||
|
|
||||||
|
$authorization->setAmount(AmountTest::createAmount());
|
||||||
|
$authorization->setLinks(array(LinkTest::createLink()));
|
||||||
|
|
||||||
|
return $authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$authorization = new Authorization();
|
||||||
|
$authorization->setCreate_time(self::$create_time);
|
||||||
|
$authorization->setId(self::$id);
|
||||||
|
$authorization->setState(self::$state);
|
||||||
|
$authorization->setParent_payment(self::$parent_payment);
|
||||||
|
$this->authorizations['partial'] = $authorization;
|
||||||
|
|
||||||
|
|
||||||
|
$this->authorizations['full'] = self::createAuthorization();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$authorization = $this->authorizations['partial'];
|
||||||
|
$this->assertEquals(self::$create_time, $authorization->getCreate_time());
|
||||||
|
$this->assertEquals(self::$id, $authorization->getId());
|
||||||
|
$this->assertEquals(self::$state, $authorization->getState());
|
||||||
|
$this->assertEquals(self::$parent_payment, $authorization->getParent_payment());
|
||||||
|
|
||||||
|
$authorization = $this->authorizations['full'];
|
||||||
|
$this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency());
|
||||||
|
$this->assertEquals(1, count($authorization->getLinks()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$a1 = $this->authorizations['partial'];
|
||||||
|
|
||||||
|
$a2 = new Authorization();
|
||||||
|
$a2->fromJson($a1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($a1, $a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
60
tests/PayPal/Test/Api/CaptureTest.php
Normal file
60
tests/PayPal/Test/Api/CaptureTest.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Capture;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class CaptureTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $captures;
|
||||||
|
|
||||||
|
public static $authorization_id = "AUTH-123";
|
||||||
|
public static $create_time = "2013-02-28T00:00:00Z";
|
||||||
|
public static $description = "Test capture";
|
||||||
|
public static $id = "C-5678";
|
||||||
|
public static $parent_payment = "PAY-123";
|
||||||
|
public static $state = "Created";
|
||||||
|
|
||||||
|
public static function createCapture() {
|
||||||
|
$capture = new Capture();
|
||||||
|
$capture->setAuthorization_id(self::$authorization_id);
|
||||||
|
$capture->setCreate_time(self::$create_time);
|
||||||
|
$capture->setDescription(self::$description);
|
||||||
|
$capture->setId(self::$id);
|
||||||
|
$capture->setParent_payment(self::$parent_payment);
|
||||||
|
$capture->setState(self::$state);
|
||||||
|
|
||||||
|
return $capture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->captures['partial'] = self::createCapture();
|
||||||
|
|
||||||
|
$capture = self::createCapture();
|
||||||
|
$capture->setAmount(AmountTest::createAmount());
|
||||||
|
$capture->setLinks(array(LinkTest::createLink()));
|
||||||
|
$this->captures['full'] = $capture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$authorization_id, $this->captures['partial']->getAuthorization_id());
|
||||||
|
$this->assertEquals(self::$create_time, $this->captures['partial']->getCreate_time());
|
||||||
|
$this->assertEquals(self::$description, $this->captures['partial']->getDescription());
|
||||||
|
$this->assertEquals(self::$id, $this->captures['partial']->getId());
|
||||||
|
$this->assertEquals(self::$parent_payment, $this->captures['partial']->getParent_payment());
|
||||||
|
$this->assertEquals(self::$state, $this->captures['partial']->getState());
|
||||||
|
|
||||||
|
$this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
|
||||||
|
$links = $this->captures['full']->getLinks();
|
||||||
|
$this->assertEquals(LinkTest::$href, $links[0]->getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$c1 = $this->captures['partial'];
|
||||||
|
|
||||||
|
$c2 = new Capture();
|
||||||
|
$c2->fromJson($c1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($c1, $c2);
|
||||||
|
}
|
||||||
|
}
|
||||||
95
tests/PayPal/Test/Api/CreditCardTest.php
Normal file
95
tests/PayPal/Test/Api/CreditCardTest.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
use PayPal\Api\CreditCard;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class CreditCardTest 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->setExpire_month(self::$expireMonth);
|
||||||
|
$card->setExpire_year(self::$expireYear);
|
||||||
|
$card->setCvv2(self::$cvv);
|
||||||
|
$card->setFirst_name(self::$firstName);
|
||||||
|
$card->setLast_name(self::$lastName);
|
||||||
|
$card->setId(self::$id);
|
||||||
|
$card->setValid_until(self::$validUntil);
|
||||||
|
$card->setState(self::$state);
|
||||||
|
$card->setPayer_id(self::$payerId);
|
||||||
|
return $card;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
|
||||||
|
$card = self::createCreditCard();
|
||||||
|
$card->setBilling_address(AddressTest::createAddress());
|
||||||
|
$card->setLinks(array(LinkTest::createLink()));
|
||||||
|
$this->cards['full'] = $card;
|
||||||
|
|
||||||
|
$card = self::createCreditCard();
|
||||||
|
$this->cards['partial'] = $card;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetters() {
|
||||||
|
$c = $this->cards['partial'];
|
||||||
|
$this->assertEquals(self::$cardType, $c->getType());
|
||||||
|
$this->assertEquals(self::$cardNumber, $c->getNumber());
|
||||||
|
$this->assertEquals(self::$expireMonth, $c->getExpire_month());
|
||||||
|
$this->assertEquals(self::$expireYear, $c->getExpire_year());
|
||||||
|
$this->assertEquals(self::$cvv, $c->getCvv2());
|
||||||
|
$this->assertEquals(self::$firstName, $c->getFirst_name());
|
||||||
|
$this->assertEquals(self::$lastName, $c->getLast_name());
|
||||||
|
$this->assertEquals(self::$id, $c->getId());
|
||||||
|
$this->assertEquals(self::$validUntil, $c->getValid_until());
|
||||||
|
$this->assertEquals(self::$state, $c->getState());
|
||||||
|
$this->assertEquals(self::$payerId, $c->getPayer_id());
|
||||||
|
|
||||||
|
$c = $this->cards['full'];
|
||||||
|
$this->assertEquals(AddressTest::$line1, $c->getBilling_address()->getLine1());
|
||||||
|
$link = $c->getLinks();
|
||||||
|
$this->assertEquals(LinkTest::$href, $link[0]->getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$c1 = $this->cards['full'];
|
||||||
|
$json = $c1->toJson();
|
||||||
|
|
||||||
|
$c2 = new CreditCard();
|
||||||
|
$c2->fromJson($json);
|
||||||
|
|
||||||
|
$this->assertEquals($c1, $c2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOperations() {
|
||||||
|
$c1 = $this->cards['full'];
|
||||||
|
|
||||||
|
// $this->assertNull($c1->getId());
|
||||||
|
$c1->create();
|
||||||
|
$this->assertNotNull($c1->getId());
|
||||||
|
|
||||||
|
$c2 = CreditCard::get($c1->getId());
|
||||||
|
$this->assertEquals($c1->getBilling_address(), $c2->getBilling_address());
|
||||||
|
$this->assertGreaterThan(0, count($c2->getLinks()));
|
||||||
|
$this->assertEquals(self::$cardType, $c2->getType());
|
||||||
|
$this->assertNotNull($c2->getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/PayPal/Test/Api/CreditCardTokenTest.php
Normal file
38
tests/PayPal/Test/Api/CreditCardTokenTest.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\CreditCardToken;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class CreditCardTokenTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $ccToken;
|
||||||
|
|
||||||
|
public static $payerId = "PAYER-123";
|
||||||
|
public static $creditCardId = "CC-123";
|
||||||
|
|
||||||
|
public static function createCreditCardToken() {
|
||||||
|
$ccToken = new CreditCardToken();
|
||||||
|
$ccToken->setPayer_id(self::$payerId);
|
||||||
|
$ccToken->setCredit_card_id(self::$creditCardId);
|
||||||
|
return $ccToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->ccToken = self::createCreditCardToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$payerId, $this->ccToken->getPayer_id());
|
||||||
|
$this->assertEquals(self::$creditCardId, $this->ccToken->getCredit_card_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$t1 = $this->ccToken;
|
||||||
|
|
||||||
|
$t2 = new CreditCardToken();
|
||||||
|
$t2->fromJson($t1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($t1, $t2);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
tests/PayPal/Test/Api/FundingInstrumentTest.php
Normal file
36
tests/PayPal/Test/Api/FundingInstrumentTest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\FundingInstrument;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class FundingInstrumentTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $fi;
|
||||||
|
|
||||||
|
public static function createFundingInstrument() {
|
||||||
|
$fi = new FundingInstrument();
|
||||||
|
$fi->setCredit_card(CreditCardTest::createCreditCard());
|
||||||
|
$fi->setCredit_card_token(CreditCardTokenTest::createCreditCardToken());
|
||||||
|
return $fi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->fi = self::createFundingInstrument();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCredit_card()->getNumber());
|
||||||
|
$this->assertEquals(CreditCardTokenTest::$creditCardId,
|
||||||
|
$this->fi->getCredit_card_token()->getCredit_card_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$fi1 = $this->fi;
|
||||||
|
|
||||||
|
$fi2 = new FundingInstrument();
|
||||||
|
$fi2->fromJson($fi1->toJson());
|
||||||
|
$this->assertEquals($fi1, $fi2);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
tests/PayPal/Test/Api/ItemListTest.php
Normal file
46
tests/PayPal/Test/Api/ItemListTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Item;
|
||||||
|
use PayPal\Api\ItemList;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class ItemListTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $items = array();
|
||||||
|
|
||||||
|
private static $name = "item name";
|
||||||
|
private static $price = "1.12";
|
||||||
|
private static $quantity = "10";
|
||||||
|
private static $sku = "AXVTY123";
|
||||||
|
private static $currency = "USD";
|
||||||
|
|
||||||
|
public static function createItemList() {
|
||||||
|
|
||||||
|
$item = ItemTest::createItem();
|
||||||
|
|
||||||
|
$itemList = new ItemList();
|
||||||
|
$itemList->setItems(array($item));
|
||||||
|
$itemList->setShipping_address(ShippingAddressTest::createAddress());
|
||||||
|
|
||||||
|
return $itemList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->items = self::createItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetters() {
|
||||||
|
$items = $this->items->getItems();
|
||||||
|
$this->assertEquals(ItemTest::createItem(), $items[0]);
|
||||||
|
$this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShipping_address());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$itemList = new ItemList();
|
||||||
|
$itemList->fromJson($this->items->toJSON());
|
||||||
|
|
||||||
|
$this->assertEquals($itemList, $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
tests/PayPal/Test/Api/ItemTest.php
Normal file
46
tests/PayPal/Test/Api/ItemTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Item;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class ItemTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $item;
|
||||||
|
|
||||||
|
public static $name = "item name";
|
||||||
|
public static $price = "1.12";
|
||||||
|
public static $quantity = "10";
|
||||||
|
public static $sku = "AXVTY123";
|
||||||
|
public static $currency = "USD";
|
||||||
|
|
||||||
|
public static function createItem() {
|
||||||
|
$item = new Item();
|
||||||
|
$item->setName(self::$name);
|
||||||
|
$item->setPrice(self::$price);
|
||||||
|
$item->setQuantity(self::$quantity);
|
||||||
|
$item->setSku(self::$sku);
|
||||||
|
$item->setCurrency(self::$currency);
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
public function setup() {
|
||||||
|
$this->item = ItemTest::createItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetters() {
|
||||||
|
$this->assertEquals(self::$name, $this->item->getName());
|
||||||
|
$this->assertEquals(self::$price, $this->item->getPrice());
|
||||||
|
$this->assertEquals(self::$sku, $this->item->getSku());
|
||||||
|
$this->assertEquals(self::$quantity, $this->item->getQuantity());
|
||||||
|
$this->assertEquals(self::$currency, $this->item->getCurrency());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$item = new Item();
|
||||||
|
$item->fromJson($this->item->toJSON());
|
||||||
|
|
||||||
|
$this->assertEquals($item, $this->item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
40
tests/PayPal/Test/Api/LinkTest.php
Normal file
40
tests/PayPal/Test/Api/LinkTest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Link;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class LinkTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $link;
|
||||||
|
|
||||||
|
public static $href = "USD";
|
||||||
|
public static $rel = "1.12";
|
||||||
|
public static $method = "1.12";
|
||||||
|
|
||||||
|
public static function createLink() {
|
||||||
|
$link = new Link();
|
||||||
|
$link->setHref(self::$href);
|
||||||
|
$link->setRel(self::$rel);
|
||||||
|
$link->setMethod(self::$method);
|
||||||
|
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->link = self::createLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetters() {
|
||||||
|
$this->assertEquals(self::$href, $this->link->getHref());
|
||||||
|
$this->assertEquals(self::$rel, $this->link->getRel());
|
||||||
|
$this->assertEquals(self::$method, $this->link->getMethod());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$link2 = new Link();
|
||||||
|
$link2->fromJson($this->link->toJSON());
|
||||||
|
$this->assertEquals($this->link, $link2);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/PayPal/Test/Api/PayeeTest.php
Normal file
44
tests/PayPal/Test/Api/PayeeTest.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Payee;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class PayeeTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $payee;
|
||||||
|
|
||||||
|
public static $email = "test@paypal.com";
|
||||||
|
public static $merchant_id = "1XY12121";
|
||||||
|
public static $phone = "+14081234566";
|
||||||
|
|
||||||
|
|
||||||
|
public static function createPayee() {
|
||||||
|
$payee = new Payee();
|
||||||
|
$payee->setEmail(self::$email);
|
||||||
|
$payee->setMerchant_id(self::$merchant_id);
|
||||||
|
$payee->setPhone(self::$phone);
|
||||||
|
|
||||||
|
return $payee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->payee = self::createPayee();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$email, $this->payee->getEmail());
|
||||||
|
$this->assertEquals(self::$merchant_id, $this->payee->getMerchant_id());
|
||||||
|
$this->assertEquals(self::$phone, $this->payee->getPhone());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$p1 = $this->payee;
|
||||||
|
|
||||||
|
$p2 = new Payee();
|
||||||
|
$p2->fromJson($p1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($p1, $p2);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
tests/PayPal/Test/Api/PayerInfoTest.php
Normal file
50
tests/PayPal/Test/Api/PayerInfoTest.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\PayerInfo;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class PayerInfoTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $payerInfo;
|
||||||
|
|
||||||
|
public static $email = "test@paypal.com";
|
||||||
|
public static $firstName = "first";
|
||||||
|
public static $lastName = "last";
|
||||||
|
public static $phone = "408-1234-5687";
|
||||||
|
public static $payerId = "PAYER-1234";
|
||||||
|
|
||||||
|
public static function createPayerInfo() {
|
||||||
|
$payerInfo = new PayerInfo();
|
||||||
|
$payerInfo->setEmail(self::$email);
|
||||||
|
$payerInfo->setFirst_name(self::$firstName);
|
||||||
|
$payerInfo->setLast_name(self::$lastName);
|
||||||
|
$payerInfo->setPhone(self::$phone);
|
||||||
|
$payerInfo->setPayer_id(self::$payerId);
|
||||||
|
$payerInfo->setShipping_address(AddressTest::createAddress());
|
||||||
|
|
||||||
|
return $payerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->payerInfo = self::createPayerInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$email, $this->payerInfo->getEmail());
|
||||||
|
$this->assertEquals(self::$firstName, $this->payerInfo->getFirst_name());
|
||||||
|
$this->assertEquals(self::$lastName, $this->payerInfo->getLast_name());
|
||||||
|
$this->assertEquals(self::$phone, $this->payerInfo->getPhone());
|
||||||
|
$this->assertEquals(self::$payerId, $this->payerInfo->getPayer_id());
|
||||||
|
$this->assertEquals(AddressTest::$line1, $this->payerInfo->getShipping_address()->getLine1());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$p1 = $this->payerInfo;
|
||||||
|
|
||||||
|
$p2 = new PayerInfo();
|
||||||
|
$p2->fromJson($p1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($p1, $p2);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
tests/PayPal/Test/Api/PayerTest.php
Normal file
45
tests/PayPal/Test/Api/PayerTest.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\FundingInstrument;
|
||||||
|
|
||||||
|
use PayPal\Api\Payer;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class PayerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $payer;
|
||||||
|
|
||||||
|
private static $paymentMethod = "credit_card";
|
||||||
|
|
||||||
|
public static function createPayer() {
|
||||||
|
$payer = new Payer();
|
||||||
|
$payer->setPayment_method(self::$paymentMethod);
|
||||||
|
$payer->setPayer_info(PayerInfoTest::createPayerInfo());
|
||||||
|
$payer->setFunding_instruments(array(FundingInstrumentTest::createFundingInstrument()));
|
||||||
|
|
||||||
|
return $payer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->payer = self::createPayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$paymentMethod, $this->payer->getPayment_method());
|
||||||
|
$this->assertEquals(PayerInfoTest::$email, $this->payer->getPayer_info()->getEmail());
|
||||||
|
|
||||||
|
$fi = $this->payer->getFunding_instruments();
|
||||||
|
$this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCredit_card_token()->getCredit_card_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$p1 = $this->payer;
|
||||||
|
|
||||||
|
$p2 = new Payer();
|
||||||
|
$p2->fromJson($p1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($p1, $p2);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
tests/PayPal/Test/Api/PaymentHistoryTest.php
Normal file
39
tests/PayPal/Test/Api/PaymentHistoryTest.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\PaymentHistory;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class PaymentHistoryTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $history;
|
||||||
|
|
||||||
|
public static $count = "10";
|
||||||
|
public static $nextId = "11";
|
||||||
|
|
||||||
|
public static function createPaymentHistory() {
|
||||||
|
$history = new PaymentHistory();
|
||||||
|
$history->setCount(self::$count);
|
||||||
|
$history->setNext_id(self::$nextId);
|
||||||
|
$history->setPayments(array(PaymentTest::createPayment()));
|
||||||
|
return $history;
|
||||||
|
}
|
||||||
|
public function setup() {
|
||||||
|
$this->history = PaymentHistoryTest::createPaymentHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetters() {
|
||||||
|
$this->assertEquals(self::$count, $this->history->getCount());
|
||||||
|
$this->assertEquals(self::$nextId, $this->history->getNext_id());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$history = new PaymentHistory();
|
||||||
|
$history->fromJson($this->history->toJSON());
|
||||||
|
|
||||||
|
$this->assertEquals($history, $this->history);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
82
tests/PayPal/Test/Api/PaymentTest.php
Normal file
82
tests/PayPal/Test/Api/PaymentTest.php
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
|
||||||
|
use PayPal\Api\RedirectUrls;
|
||||||
|
|
||||||
|
use PayPal\Api\Address;
|
||||||
|
use PayPal\Api\Amount;
|
||||||
|
use PayPal\Api\CreditCard;
|
||||||
|
use PayPal\Api\Payer;
|
||||||
|
use PayPal\Api\Payment;
|
||||||
|
use PayPal\Api\FundingInstrument;
|
||||||
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class PaymentTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $payments;
|
||||||
|
|
||||||
|
public static function createPayment() {
|
||||||
|
|
||||||
|
$redirectUrls = new RedirectUrls();
|
||||||
|
$redirectUrls->setReturn_url("http://localhost/return");
|
||||||
|
$redirectUrls->setCancel_url("http://localhost/cancel");
|
||||||
|
|
||||||
|
$payment = new Payment();
|
||||||
|
$payment->setIntent("sale");
|
||||||
|
$payment->setRedirect_urls($redirectUrls);
|
||||||
|
$payment->setPayer(PayerTest::createPayer());
|
||||||
|
$payment->setTransactions(array(TransactionTest::createTransaction()));
|
||||||
|
|
||||||
|
return $payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createNewPayment() {
|
||||||
|
$payer = new Payer();
|
||||||
|
$payer->setPayment_method("credit_card");
|
||||||
|
$payer->setFunding_instruments(array(FundingInstrumentTest::createFundingInstrument()));
|
||||||
|
|
||||||
|
$transaction = new Transaction();
|
||||||
|
$transaction->setAmount(AmountTest::createAmount());
|
||||||
|
$transaction->setDescription("This is the payment description.");
|
||||||
|
|
||||||
|
$redirectUrls = new RedirectUrls();
|
||||||
|
$redirectUrls->setReturn_url("http://localhost/return");
|
||||||
|
$redirectUrls->setCancel_url("http://localhost/cancel");
|
||||||
|
|
||||||
|
$payment = new Payment();
|
||||||
|
$payment->setIntent("sale");
|
||||||
|
$payment->setRedirect_urls($redirectUrls);
|
||||||
|
$payment->setPayer($payer);
|
||||||
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
|
return $payment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->payments['full'] = self::createPayment();
|
||||||
|
$this->payments['new'] = self::createNewPayment();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$p2 = new Payment();
|
||||||
|
$p2->fromJson($this->payments['full']->toJSON());
|
||||||
|
$this->assertEquals($p2, $this->payments['full']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOperations() {
|
||||||
|
|
||||||
|
$p1 = $this->payments['new'];
|
||||||
|
|
||||||
|
$p1->create();
|
||||||
|
$this->assertNotNull($p1->getId());
|
||||||
|
|
||||||
|
$p2 = Payment::get($p1->getId());
|
||||||
|
$this->assertNotNull($p2);
|
||||||
|
|
||||||
|
$paymentHistory = Payment::all(array('count' => '10'));
|
||||||
|
$this->assertNotNull($paymentHistory);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
tests/PayPal/Test/Api/RefundTest.php
Normal file
57
tests/PayPal/Test/Api/RefundTest.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Refund;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class RefundTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $refund;
|
||||||
|
|
||||||
|
public static $captureId = "CAP-123";
|
||||||
|
public static $createTime = "2013-02-28T00:00:00Z";
|
||||||
|
public static $description = "Test refund";
|
||||||
|
public static $id = "R-5678";
|
||||||
|
public static $parentPayment = "PAY-123";
|
||||||
|
|
||||||
|
public static function createRefund() {
|
||||||
|
$refund = new Refund();
|
||||||
|
$refund->setAmount(AmountTest::createAmount());
|
||||||
|
$refund->setCapture_id(self::$captureId);
|
||||||
|
$refund->setCreate_time(self::$createTime);
|
||||||
|
$refund->setDescription(self::$description);
|
||||||
|
$refund->setId(self::$id);
|
||||||
|
$refund->setLinks(array(LinkTest::createLink()));
|
||||||
|
$refund->setParent_payment(self::$parentPayment);
|
||||||
|
|
||||||
|
return $refund;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->refund = self::createRefund();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$captureId, $this->refund->getCapture_id());
|
||||||
|
$this->assertEquals(self::$createTime, $this->refund->getCreate_time());
|
||||||
|
$this->assertEquals(self::$description, $this->refund->getDescription());
|
||||||
|
$this->assertEquals(self::$id, $this->refund->getId());
|
||||||
|
$this->assertEquals(self::$parentPayment, $this->refund->getParent_payment());
|
||||||
|
$this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency());
|
||||||
|
$links = $this->refund->getLinks();
|
||||||
|
$this->assertEquals(LinkTest::$href, $links[0]->getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$r1 = $this->refund;
|
||||||
|
|
||||||
|
$r2 = new Refund();
|
||||||
|
$r2->fromJson($r1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($r1, $r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOperations() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
74
tests/PayPal/Test/Api/SaleTest.php
Normal file
74
tests/PayPal/Test/Api/SaleTest.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\Refund;
|
||||||
|
use PayPal\Api\Sale;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
use PayPal\Test\Api\AmountTest;
|
||||||
|
use PayPal\Test\Api\PaymentTest;
|
||||||
|
use PayPal\Test\Api\LinkTest;
|
||||||
|
|
||||||
|
class SaleTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $sale;
|
||||||
|
|
||||||
|
public static $captureId = "CAP-123";
|
||||||
|
public static $createTime = "2013-02-28T00:00:00Z";
|
||||||
|
public static $description = "Test refund";
|
||||||
|
public static $id = "R-5678";
|
||||||
|
public static $parentPayment = "PAY-123";
|
||||||
|
public static $state = "Created";
|
||||||
|
|
||||||
|
public static function createSale() {
|
||||||
|
$sale = new Sale();
|
||||||
|
$sale->setAmount(AmountTest::createAmount());
|
||||||
|
$sale->setCreate_time(self::$createTime);
|
||||||
|
$sale->setId(self::$id);
|
||||||
|
$sale->setLinks(array(LinkTest::createLink()));
|
||||||
|
$sale->setParent_payment(self::$parentPayment);
|
||||||
|
$sale->setState(self::$state);
|
||||||
|
return $sale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->sale = self::createSale();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$createTime, $this->sale->getCreate_time());
|
||||||
|
$this->assertEquals(self::$id, $this->sale->getId());
|
||||||
|
$this->assertEquals(self::$parentPayment, $this->sale->getParent_payment());
|
||||||
|
$this->assertEquals(self::$state, $this->sale->getState());
|
||||||
|
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
|
||||||
|
$links = $this->sale->getLinks();
|
||||||
|
$this->assertEquals(LinkTest::$href, $links[0]->getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$s1 = $this->sale;
|
||||||
|
|
||||||
|
$s2 = new Sale();
|
||||||
|
$s2->fromJson($s1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($s1, $s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOperations() {
|
||||||
|
$payment = PaymentTest::createNewPayment();
|
||||||
|
$payment->create();
|
||||||
|
|
||||||
|
$transactions = $payment->getTransactions();
|
||||||
|
$resources = $transactions[0]->getRelated_resources();
|
||||||
|
$saleId = $resources[0]->getSale()->getId();
|
||||||
|
|
||||||
|
$sale = Sale::get($saleId);
|
||||||
|
$this->assertNotNull($sale);
|
||||||
|
|
||||||
|
$refund = new Refund();
|
||||||
|
$refund->setAmount(AmountTest::createAmount());
|
||||||
|
$sale->refund($refund);
|
||||||
|
|
||||||
|
$this->setExpectedException('\InvalidArgumentException');
|
||||||
|
$sale->refund(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
tests/PayPal/Test/Api/ShippingAddressTest.php
Normal file
59
tests/PayPal/Test/Api/ShippingAddressTest.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\ShippingAddress;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class ShippingAddressTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $address;
|
||||||
|
|
||||||
|
public static $line1 = "3909 Witmer Road";
|
||||||
|
public static $line2 = "Niagara Falls";
|
||||||
|
public static $city = "Niagara Falls";
|
||||||
|
public static $state = "NY";
|
||||||
|
public static $postalCode = "14305";
|
||||||
|
public static $countryCode = "US";
|
||||||
|
public static $phone = "716-298-1822";
|
||||||
|
public static $recipientName = "TestUser";
|
||||||
|
public static $type = "Billing";
|
||||||
|
|
||||||
|
public static function createAddress() {
|
||||||
|
$addr = new ShippingAddress();
|
||||||
|
$addr->setLine1(self::$line1);
|
||||||
|
$addr->setLine2(self::$line2);
|
||||||
|
$addr->setCity(self::$city);
|
||||||
|
$addr->setState(self::$state);
|
||||||
|
$addr->setPostal_code(self::$postalCode);
|
||||||
|
$addr->setCountry_code(self::$countryCode);
|
||||||
|
$addr->setPhone(self::$phone);
|
||||||
|
$addr->setRecipient_name(self::$recipientName);
|
||||||
|
$addr->setType(self::$type);
|
||||||
|
return $addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->address = self::createAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(self::$line1, $this->address->getLine1());
|
||||||
|
$this->assertEquals(self::$line2, $this->address->getLine2());
|
||||||
|
$this->assertEquals(self::$city, $this->address->getCity());
|
||||||
|
$this->assertEquals(self::$state, $this->address->getState());
|
||||||
|
$this->assertEquals(self::$postalCode, $this->address->getPostal_code());
|
||||||
|
$this->assertEquals(self::$countryCode, $this->address->getCountry_code());
|
||||||
|
$this->assertEquals(self::$phone, $this->address->getPhone());
|
||||||
|
$this->assertEquals(self::$recipientName, $this->address->getRecipient_name());
|
||||||
|
$this->assertEquals(self::$type, $this->address->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$a1 = $this->address;
|
||||||
|
|
||||||
|
$a2 = new ShippingAddress();
|
||||||
|
$a2->fromJson($a1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($a1, $a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
tests/PayPal/Test/Api/SubTransactionTest.php
Normal file
35
tests/PayPal/Test/Api/SubTransactionTest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\SubTransaction;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class SubTransactionTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $subTransaction;
|
||||||
|
|
||||||
|
public static function createSubTransaction() {
|
||||||
|
$subTransaction = new SubTransaction();
|
||||||
|
$subTransaction->setAuthorization(AuthorizationTest::createAuthorization());
|
||||||
|
$subTransaction->setCapture(CaptureTest::createCapture());
|
||||||
|
return $subTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->subTransaction = self::createSubTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(AuthorizationTest::$create_time, $this->subTransaction->getAuthorization()->getCreate_Time());
|
||||||
|
$this->assertEquals(CaptureTest::$create_time, $this->subTransaction->getCapture()->getCreate_Time());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$s1 = $this->subTransaction;
|
||||||
|
|
||||||
|
$s2 = new SubTransaction();
|
||||||
|
$s2->fromJson($s1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($s1, $s2);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
tests/PayPal/Test/Api/TransactionTest.php
Normal file
49
tests/PayPal/Test/Api/TransactionTest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PayPal\Test\Api;
|
||||||
|
|
||||||
|
use PayPal\Api\SubTransaction;
|
||||||
|
|
||||||
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class TransactionTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $transaction;
|
||||||
|
|
||||||
|
public static $description = "desc . . . ";
|
||||||
|
public static $total = "1.12";
|
||||||
|
|
||||||
|
public static function createTransaction() {
|
||||||
|
$transaction = new Transaction();
|
||||||
|
$transaction->setAmount(AmountTest::createAmount());
|
||||||
|
$transaction->setDescription(self::$description);
|
||||||
|
$transaction->setItem_list(ItemListTest::createItemList());
|
||||||
|
$transaction->setPayee(PayeeTest::createPayee());
|
||||||
|
$transaction->setRelated_resources( array(SubTransactionTest::createSubTransaction()) );
|
||||||
|
return $transaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setup() {
|
||||||
|
$this->transaction = self::createTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetterSetter() {
|
||||||
|
$this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency());
|
||||||
|
$this->assertEquals(self::$description, $this->transaction->getDescription());
|
||||||
|
$items = $this->transaction->getItem_list()->getItems();
|
||||||
|
$this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity());
|
||||||
|
$this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail());
|
||||||
|
$resources = $this->transaction->getRelated_resources();
|
||||||
|
$this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreate_Time());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSerializeDeserialize() {
|
||||||
|
$t1 = $this->transaction;
|
||||||
|
|
||||||
|
$t2 = new Transaction();
|
||||||
|
$t2->fromJson($t1->toJson());
|
||||||
|
|
||||||
|
$this->assertEquals($t1, $t2);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
tests/PayPal/Test/Auth/OAuthTokenCredentialTest.php
Normal file
33
tests/PayPal/Test/Auth/OAuthTokenCredentialTest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// namespace PayPal\Test\Common;
|
||||||
|
|
||||||
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
public function testGetAccessToken() {
|
||||||
|
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
|
||||||
|
|
||||||
|
$token = $cred->getAccessToken();
|
||||||
|
$this->assertNotNull($token);
|
||||||
|
|
||||||
|
// Check that we get the same token when issuing a new call before token expiry
|
||||||
|
$newToken = $cred->getAccessToken();
|
||||||
|
$this->assertNotNull($newToken);
|
||||||
|
$this->assertEquals($token, $newToken);
|
||||||
|
|
||||||
|
// sleep(60*8);
|
||||||
|
// $newToken = $cred->getAccessToken();
|
||||||
|
// $this->assertNotNull($newToken);
|
||||||
|
// $this->assertNotEqual($token, $newToken);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvalidCredentials() {
|
||||||
|
$this->setExpectedException('\PPConnectionException');
|
||||||
|
$cred = new OAuthTokenCredential('dummy', 'secret');
|
||||||
|
$this->assertNull($cred->getAccessToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
22
tests/PayPal/Test/Common/ArrayUtilTest.php
Normal file
22
tests/PayPal/Test/Common/ArrayUtilTest.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
// namespace PayPal\Test\Common;
|
||||||
|
|
||||||
|
use PayPal\Common\ArrayUtil;
|
||||||
|
|
||||||
|
class ArrayUtilTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
public function testIsAssocArray() {
|
||||||
|
|
||||||
|
$arr = array(1, 2, 3);
|
||||||
|
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
|
||||||
|
|
||||||
|
$arr = array(
|
||||||
|
'name' => 'John Doe',
|
||||||
|
'City' => 'San Jose'
|
||||||
|
);
|
||||||
|
$this->assertEquals(true, ArrayUtil::isAssocArray($arr));
|
||||||
|
|
||||||
|
$arr[] = 'CA';
|
||||||
|
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
|
||||||
|
}
|
||||||
|
}
|
||||||
135
tests/PayPal/Test/Common/ModelTest.php
Normal file
135
tests/PayPal/Test/Common/ModelTest.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// namespace PayPal\Test\Common;
|
||||||
|
|
||||||
|
use PayPal\Common\Model;
|
||||||
|
|
||||||
|
class SimpleClass extends Model {
|
||||||
|
|
||||||
|
public function setName($name) {
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
public function getName() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription($desc) {
|
||||||
|
$this->desc = $desc;
|
||||||
|
}
|
||||||
|
public function getDescription() {
|
||||||
|
return $this->desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ArrayClass extends Model {
|
||||||
|
|
||||||
|
public function setName($name) {
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
public function getName() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription($desc) {
|
||||||
|
$this->desc = $desc;
|
||||||
|
}
|
||||||
|
public function getDescription() {
|
||||||
|
return $this->desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTags($tags) {
|
||||||
|
if(!is_array($tags)) {
|
||||||
|
$tags = array($tags);
|
||||||
|
}
|
||||||
|
$this->tags = $tags;
|
||||||
|
}
|
||||||
|
public function getTags() {
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NestedClass extends Model {
|
||||||
|
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param ArrayClass $info
|
||||||
|
*/
|
||||||
|
public function setInfo($info) {
|
||||||
|
$this->info = $info;
|
||||||
|
}
|
||||||
|
public function getInfo() {
|
||||||
|
return $this->info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChildClass extends SimpleClass {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class ModelTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
public function testSimpleClassConversion() {
|
||||||
|
$o = new SimpleClass();
|
||||||
|
$o->setName("test");
|
||||||
|
$o->setDescription("description");
|
||||||
|
|
||||||
|
$this->assertEquals("test", $o->getName());
|
||||||
|
$this->assertEquals("description", $o->getDescription());
|
||||||
|
|
||||||
|
$json = $o->toJSON();
|
||||||
|
$this->assertEquals('{"name":"test","desc":"description"}', $json);
|
||||||
|
|
||||||
|
$newO = new SimpleClass();
|
||||||
|
$newO->fromJson($json);
|
||||||
|
$this->assertEquals($o, $newO);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testArrayClassConversion() {
|
||||||
|
$o = new ArrayClass();
|
||||||
|
$o->setName("test");
|
||||||
|
$o->setDescription("description");
|
||||||
|
$o->setTags(array('payment', 'info', 'test'));
|
||||||
|
|
||||||
|
$this->assertEquals("test", $o->getName());
|
||||||
|
$this->assertEquals("description", $o->getDescription());
|
||||||
|
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
|
||||||
|
|
||||||
|
$json = $o->toJSON();
|
||||||
|
$this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json);
|
||||||
|
|
||||||
|
$newO = new ArrayClass();
|
||||||
|
$newO->fromJson($json);
|
||||||
|
$this->assertEquals($o, $newO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedClassConversion() {
|
||||||
|
$n = new ArrayClass();
|
||||||
|
$n->setName("test");
|
||||||
|
$n->setDescription("description");
|
||||||
|
// $n->setTags(array('payment', 'info', 'test'));
|
||||||
|
$o = new NestedClass();
|
||||||
|
$o->setId('123');
|
||||||
|
$o->setInfo($n);
|
||||||
|
|
||||||
|
$this->assertEquals("123", $o->getId());
|
||||||
|
$this->assertEquals("test", $o->getInfo()->getName());
|
||||||
|
// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
|
||||||
|
|
||||||
|
$json = $o->toJSON();
|
||||||
|
// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
|
||||||
|
$this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
|
||||||
|
|
||||||
|
$newO = new NestedClass();
|
||||||
|
$newO->fromJson($json);
|
||||||
|
$this->assertEquals($o, $newO);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
tests/PayPal/Test/Common/UserAgentTest.php
Normal file
23
tests/PayPal/Test/Common/UserAgentTest.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PayPal\Common\UserAgent;
|
||||||
|
|
||||||
|
class UserAgentTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
public function testGetValue() {
|
||||||
|
$ua = UserAgent::getValue();
|
||||||
|
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
|
||||||
|
|
||||||
|
// Check that we pass the useragent in the expected format
|
||||||
|
$this->assertNotNull($id);
|
||||||
|
$this->assertNotNull($version);
|
||||||
|
$this->assertNotNull($features);
|
||||||
|
|
||||||
|
// Check that we pass in these mininal features
|
||||||
|
$this->assertThat($features, $this->stringContains("OS="));
|
||||||
|
$this->assertThat($features, $this->stringContains("Bit="));
|
||||||
|
$this->assertThat($features, $this->stringContains("Lang="));
|
||||||
|
$this->assertThat($features, $this->stringContains("V="));
|
||||||
|
$this->assertGreaterThan(5, count(explode(';', $features)));
|
||||||
|
}
|
||||||
|
}
|
||||||
7
tests/PayPal/Test/Constants.php
Normal file
7
tests/PayPal/Test/Constants.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
namespace PayPal\Test;
|
||||||
|
|
||||||
|
class Constants {
|
||||||
|
const CLIENT_ID = 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM';
|
||||||
|
const CLIENT_SECRET = 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM';
|
||||||
|
}
|
||||||
41
tests/PayPal/Test/Rest/CallTest.php
Normal file
41
tests/PayPal/Test/Rest/CallTest.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// namespace PayPal\Test\Rest;
|
||||||
|
|
||||||
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
|
||||||
|
use PayPal\Rest\Call;
|
||||||
|
use PayPal\Test\Constants;
|
||||||
|
|
||||||
|
class CallTest {
|
||||||
|
|
||||||
|
public function testExecuteWithExplicitCredentials() {
|
||||||
|
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
|
||||||
|
$data = '"request":"test message"';
|
||||||
|
|
||||||
|
$call = new Call();
|
||||||
|
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
|
||||||
|
$this->assertEquals($data, $ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExecuteWithInvalidCredentials() {
|
||||||
|
|
||||||
|
$cred = new OAuthTokenCredential('test', 'dummy');
|
||||||
|
$data = '"request":"test message"';
|
||||||
|
|
||||||
|
$call = new Call();
|
||||||
|
$this->setExpectedException('\PPConnectionException');
|
||||||
|
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testExecuteWithDefaultCredentials() {
|
||||||
|
|
||||||
|
$data = '"request":"test message"';
|
||||||
|
|
||||||
|
$call = new Call();
|
||||||
|
$ret = $call->execute('/v1/payments/echo', "POST", $data);
|
||||||
|
$this->assertEquals($data, $ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
tests/bootstrap.php
Normal file
6
tests/bootstrap.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Include the composer autoloader
|
||||||
|
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
$loader->add('PayPal\\Test', __DIR__);
|
||||||
|
define("PP_CONFIG_PATH", __DIR__);
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user