forked from LiveCarta/PayPal-PHP-SDK
Updates to Sample Code
- Updated UI Presentation on samples - Fixed Bugs
This commit is contained in:
@@ -247,7 +247,7 @@ class Payment extends ResourceModel
|
||||
* A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee
|
||||
*
|
||||
*
|
||||
* @param \PayPal\Api\Transaction $transactions
|
||||
* @param \PayPal\Api\Transaction[] $transactions
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
|
||||
@@ -14,14 +14,18 @@ class JsonValidator
|
||||
* Helper method for validating if string provided is a valid json.
|
||||
*
|
||||
* @param string $string String representation of Json object
|
||||
* @param bool $silent Flag to not throw \InvalidArgumentException
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($string)
|
||||
public static function validate($string, $silent = false)
|
||||
{
|
||||
json_decode($string);
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
//Throw an Exception for string or array
|
||||
throw new \InvalidArgumentException("Invalid JSON String");
|
||||
if ($silent == false) {
|
||||
//Throw an Exception for string or array
|
||||
throw new \InvalidArgumentException("Invalid JSON String");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class ModelAccessorValidator
|
||||
if (!method_exists($class, $methodName)) {
|
||||
//Delegate the error based on the choice
|
||||
$className = is_object($class) ? get_class($class) : (string)$class;
|
||||
$errorMessage = "Missing Accessor: $className:$methodName. Please let us know by creating an issue at https://github.com/paypal/rest-api-sdk-php/issues";
|
||||
$errorMessage = "Missing Accessor: $className:$methodName. Please let us know by creating an issue at https://github.com/paypal/PayPal-PHP-SDK/issues";
|
||||
PPLoggingManager::getInstance(__CLASS__)->warning($errorMessage);
|
||||
if ($mode == 'strict') {
|
||||
trigger_error($errorMessage, E_USER_NOTICE);
|
||||
|
||||
@@ -100,9 +100,8 @@ try {
|
||||
// Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
|
||||
$agreement = $agreement->create($apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,9 +80,8 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ $merchantPreferences = new MerchantPreferences();
|
||||
$baseUrl = getBaseUrl();
|
||||
$merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true")
|
||||
->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false")
|
||||
->setAutoBillAmount("YES")
|
||||
->setAutoBillAmount("yes")
|
||||
->setInitialFailAmountAction("CONTINUE")
|
||||
->setMaxFailAttempts("0")
|
||||
->setSetupFee(new Currency(['value' => '1', 'currency' => 'USD']));
|
||||
@@ -61,9 +61,8 @@ $request = clone $plan;
|
||||
// ### Create Plan
|
||||
try {
|
||||
$output = $plan->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
try {
|
||||
$agreement->execute($token, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
|
||||
exit(1);
|
||||
}
|
||||
ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);
|
||||
|
||||
@@ -14,9 +14,8 @@ use PayPal\Api\Agreement;
|
||||
|
||||
try {
|
||||
$agreement = Agreement::get($createdAgreement->getId(), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@ use PayPal\Api\Plan;
|
||||
|
||||
try {
|
||||
$plan = Plan::get($createdPlan->getId(), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Retrieved a Plan", "Plan", $plan->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@ try {
|
||||
// at https://developer.paypal.com/webapps/developer/docs/api/#list-plans
|
||||
$params = array('page_size' => '2');
|
||||
$planList = Plan::all($params, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,8 @@ try {
|
||||
// Lets get the updated Agreement Object
|
||||
$agreement = Agreement::get($suspendedAgreement->getId(), $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,8 @@ try {
|
||||
// Lets get the updated Agreement Object
|
||||
$agreement = Agreement::get($createdAgreement->getId(), $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Suspended the Agreement", "Agreement", null, $agreementStateDescriptor, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,8 @@ try {
|
||||
// Lets get the updated Agreement Object
|
||||
$agreement = Agreement::get($createdAgreement->getId(), $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", null, $patchRequest, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,8 @@ try {
|
||||
|
||||
$plan = Plan::get($createdPlan->getId(), $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,22 @@ use PayPal\Api\FundingInstrument;
|
||||
*
|
||||
* Class ResultPrinter
|
||||
*/
|
||||
class ResultPrinter {
|
||||
class ResultPrinter
|
||||
{
|
||||
|
||||
private static $printResultCounter = 0;
|
||||
|
||||
public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null)
|
||||
/**
|
||||
* Prints HTML Output to web page.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $objectName
|
||||
* @param string $objectId
|
||||
* @param mixed $request
|
||||
* @param mixed $response
|
||||
* @param string $error
|
||||
*/
|
||||
public static function printOutput($title, $objectName, $objectId = null, $request = null, $response = null, $errorMessage = null)
|
||||
{
|
||||
if (self::$printResultCounter == 0) {
|
||||
include "header.html";
|
||||
@@ -33,10 +44,10 @@ class ResultPrinter {
|
||||
self::$printResultCounter++;
|
||||
echo '
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading" role="tab" id="heading-'.self::$printResultCounter.'">
|
||||
<div class="panel-heading '. ($errorMessage ? 'error' : '') .'" role="tab" id="heading-'.self::$printResultCounter.'">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#step-'. self::$printResultCounter .'" aria-expanded="false" aria-controls="step-'.self::$printResultCounter.'">
|
||||
'. self::$printResultCounter .'. '. $title .'</a>
|
||||
'. self::$printResultCounter .'. '. $title . ($errorMessage ? ' (Failed)' : '') . '</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="step-'.self::$printResultCounter.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-'. self::$printResultCounter . '">
|
||||
@@ -44,13 +55,13 @@ class ResultPrinter {
|
||||
';
|
||||
|
||||
if ($objectId) {
|
||||
echo '<div>' . ($objectName ? $objectName : "Object") . " with ID: $objectId </div>";
|
||||
echo "<div>" . ($objectName ? $objectName : "Object") . " with ID: $objectId </div>";
|
||||
}
|
||||
|
||||
echo '<div class="row hidden-xs hidden-sm hidden-md"><div class="col-md-6"><h4>Request Object</h4>';
|
||||
self::printObject($request);
|
||||
echo '</div><div class="col-md-6"><h4>Response Object</h4>';
|
||||
self::printObject($response);
|
||||
echo '</div><div class="col-md-6"><h4 class="'. ($errorMessage ? 'error' : '') .'">Response Object</h4>';
|
||||
self::printObject($response, $errorMessage);
|
||||
echo '</div></div>';
|
||||
|
||||
echo '<div class="hidden-lg"><ul class="nav nav-tabs" role="tablist">
|
||||
@@ -61,7 +72,7 @@ class ResultPrinter {
|
||||
<div role="tabpanel" class="tab-pane" id="step-'.self::$printResultCounter .'-request"><h4>Request Object</h4>';
|
||||
self::printObject($request) ;
|
||||
echo '</div><div role="tabpanel" class="tab-pane active" id="step-'.self::$printResultCounter .'-response"><h4>Response Object</h4>';
|
||||
self::printObject($response);
|
||||
self::printObject($response, $errorMessage);
|
||||
echo '</div></div></div></div>
|
||||
</div>
|
||||
</div>';
|
||||
@@ -69,14 +80,51 @@ class ResultPrinter {
|
||||
flush();
|
||||
}
|
||||
|
||||
protected static function printObject($object)
|
||||
/**
|
||||
* Prints success response HTML Output to web page.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $objectName
|
||||
* @param string $objectId
|
||||
* @param mixed $request
|
||||
* @param mixed $response
|
||||
*/
|
||||
public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null)
|
||||
{
|
||||
self::printOutput($title, $objectName, $objectId, $request, $response, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Error
|
||||
*
|
||||
* @param $title
|
||||
* @param $objectName
|
||||
* @param null $objectId
|
||||
* @param null $request
|
||||
* @param \Exception $exception
|
||||
*/
|
||||
public static function printError($title, $objectName, $objectId = null, $request = null, $exception = null)
|
||||
{
|
||||
$data = null;
|
||||
if ($exception instanceof \PayPal\Exception\PPConnectionException) {
|
||||
$data = $exception->getData();
|
||||
}
|
||||
self::printOutput($title, $objectName, $objectId, $request, $data, $exception->getMessage());
|
||||
}
|
||||
|
||||
protected static function printObject($object, $error = null)
|
||||
{
|
||||
if ($error) {
|
||||
echo '<pre class="error">'. $error . '</pre>';
|
||||
}
|
||||
if ($object) {
|
||||
if (is_a($object, 'PayPal\Common\PPModel')) {
|
||||
/** @var $object \PayPal\Common\PPModel */
|
||||
echo '<pre class="prettyprint">' . $object->toJSON(128) . "</pre>";
|
||||
echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">' . $object->toJSON(128) . "</pre>";
|
||||
} elseif (\PayPal\Validation\JsonValidator::validate($object, true)) {
|
||||
echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">'. str_replace('\\/', '/', json_encode(json_decode($object), 128)) . "</pre>";
|
||||
} elseif (is_string($object)) {
|
||||
echo "<pre>$object</pre>";
|
||||
echo '<pre class="prettyprint '. ($error ? 'error' : '') .'">' . $object . '</pre>';
|
||||
} else {
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
@@ -111,59 +159,3 @@ function getBaseUrl()
|
||||
$request = $_SERVER['PHP_SELF'];
|
||||
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new mock 'payment authorization'
|
||||
*
|
||||
* @param PayPal\Api\ApiContext apiContext
|
||||
* @return PayPal\Api\Authorization
|
||||
*/
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road")
|
||||
->setLine2("Niagara Falls")
|
||||
->setCity("Niagara Falls")
|
||||
->setState("NY")
|
||||
->setPostalCode("14305")
|
||||
->setCountryCode("US")
|
||||
->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper")
|
||||
->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("Payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
|
||||
// Setting intent to authorize creates a payment
|
||||
// authorization. Setting it to sale creates actual payment
|
||||
$payment->setIntent("authorize")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
@@ -1107,6 +1107,46 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
"language": {
|
||||
"nameMatchers": [{}, ".fbp"],
|
||||
"pygmentsLexer": "php",
|
||||
"singleLineComment": ["//"],
|
||||
"ignorePrefix": "}",
|
||||
"foldPrefix": "^",
|
||||
"name": "PHP"
|
||||
},
|
||||
"sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/AuthorizePayment.php",
|
||||
"projectPath": "payments/AuthorizePayment.php",
|
||||
"targetPath": "payments/AuthorizePayment",
|
||||
"pageTitle": "payments/AuthorizePayment",
|
||||
"title": "AuthorizePayment"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Authorize Payment",
|
||||
"slug": "authorize-payment"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Create Payment",
|
||||
"slug": "create-payment"
|
||||
},
|
||||
"depth": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
@@ -1399,14 +1439,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
"slug": "get-redirect-url"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Redirect buyer to PayPal website",
|
||||
"slug": "redirect-buyer-to-paypal-website"
|
||||
},
|
||||
"depth": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1613,14 +1645,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Create a mock Capture",
|
||||
"slug": "create-a-mock-capture"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
@@ -1748,14 +1772,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
"slug": "reauthorization"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Lookup authorization using the authorization id",
|
||||
"slug": "lookup-authorization-using-the-authorization-id"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
@@ -1797,14 +1813,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Capture",
|
||||
"slug": "capture"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
@@ -1895,6 +1903,14 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Get Sale From Created Payment",
|
||||
"slug": "get-sale-from-created-payment"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
@@ -2049,22 +2065,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "CreditCard",
|
||||
"slug": "creditcard"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Save card",
|
||||
"slug": "save-card"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
|
||||
@@ -74,9 +74,8 @@ Please note that the plan Id should be only set in this case.</p></div></div><di
|
||||
->setCountryCode(<span class="hljs-string">'US'</span>);
|
||||
<span class="hljs-variable">$agreement</span>->setShippingAddress(<span class="hljs-variable">$shippingAddress</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$agreement</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-agreement">Create Agreement</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = <span class="hljs-variable">$agreement</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Created Billing Agreement."</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +54,8 @@ method</p></div></div><div class="code"><div class="wrapper"> <span class="hl
|
||||
}
|
||||
}
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Created Billing Agreement."</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ You should be able to see the acceptable values in the comments.</p></div></div>
|
||||
<span class="hljs-variable">$baseUrl</span> = getBaseUrl();
|
||||
<span class="hljs-variable">$merchantPreferences</span>->setReturnUrl(<span class="hljs-string">"$baseUrl/ExecuteAgreement.php?success=true"</span>)
|
||||
->setCancelUrl(<span class="hljs-string">"$baseUrl/ExecuteAgreement.php?success=false"</span>)
|
||||
->setAutoBillAmount(<span class="hljs-string">"YES"</span>)
|
||||
->setAutoBillAmount(<span class="hljs-string">"yes"</span>)
|
||||
->setInitialFailAmountAction(<span class="hljs-string">"CONTINUE"</span>)
|
||||
->setMaxFailAttempts(<span class="hljs-string">"0"</span>)
|
||||
->setSetupFee(<span class="hljs-keyword">new</span> Currency([<span class="hljs-string">'value'</span> => <span class="hljs-string">'1'</span>, <span class="hljs-string">'currency'</span> => <span class="hljs-string">'USD'</span>]));
|
||||
@@ -35,9 +35,8 @@ You should be able to see the acceptable values in the comments.</p></div></div>
|
||||
<span class="hljs-variable">$plan</span>->setPaymentDefinitions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$paymentDefinition</span>));
|
||||
<span class="hljs-variable">$plan</span>->setMerchantPreferences(<span class="hljs-variable">$merchantPreferences</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$plan</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-plan">Create Plan</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$output</span> = <span class="hljs-variable">$plan</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Created Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,8 @@ session_start();
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$agreement</span>->execute(<span class="hljs-variable">$token</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Executed an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>], <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Executed an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>], <span class="hljs-variable">$agreement</span>);
|
||||
|
||||
@@ -8,9 +8,8 @@ API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><d
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Retrieved an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$createdAgreement</span>->getId(), <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,8 @@ API used: /v1/payments/billing-plans</p></div></div></div><div class="segment"><
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$plan</span> = Plan::get(<span class="hljs-variable">$createdPlan</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Retrieved a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,8 @@ You can modify different params to change the return list.
|
||||
The explanation about each pagination information could be found here
|
||||
at <a href="https://developer.paypal.com/webapps/developer/docs/api/#list-plans">https://developer.paypal.com/webapps/developer/docs/api/#list-plans</a></p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$params</span> = <span class="hljs-keyword">array</span>(<span class="hljs-string">'page_size'</span> => <span class="hljs-string">'2'</span>);
|
||||
<span class="hljs-variable">$planList</span> = Plan::all(<span class="hljs-variable">$params</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"List of Plans"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@ API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend</p></div></div>
|
||||
|
||||
<span class="hljs-variable">$suspendedAgreement</span>->reActivate(<span class="hljs-variable">$agreementStateDescriptor</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lets get the updated Agreement Object</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$suspendedAgreement</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Reactivate the Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$suspendedAgreement</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@ API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend</p></div></div>
|
||||
|
||||
<span class="hljs-variable">$createdAgreement</span>->suspend(<span class="hljs-variable">$agreementStateDescriptor</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lets get the updated Agreement Object</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Suspended the Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$agreementStateDescriptor</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,8 @@ API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><d
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$createdAgreement</span>->update(<span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lets get the updated Agreement Object</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Updated the Agreement with new Description and Updated Shipping Address"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,8 @@ API used: /v1/payments/billing-plans/<Plan-Id></p></div></div></div><div class=
|
||||
|
||||
<span class="hljs-variable">$plan</span> = Plan::get(<span class="hljs-variable">$createdPlan</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Updated the Plan to Active State"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,8 @@ static <code>cancel</code> method
|
||||
on the Invoice class by passing a valid
|
||||
notification object
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$cancelStatus</span> = <span class="hljs-variable">$invoice</span>->cancel(<span class="hljs-variable">$notify</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Cancel Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$notify</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,9 +74,8 @@ detailed breakdown of invoice</p></div></div><div class="code"><div class="wrapp
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-invoice">Create Invoice</h3>
|
||||
<p>Create an invoice by calling the invoice->create() method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$invoice</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Invoice Creation"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,8 @@ on the Invoice class by passing a valid
|
||||
Invoice ID
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$invoice</span> = Invoice::get(<span class="hljs-variable">$invoiceId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-variable">$invoice</span>->getId(), <span class="hljs-variable">$invoiceId</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,8 @@ all invoice from history.</p></div></div><div class="code"><div class="wrapper">
|
||||
static <code>get_all</code> method on the Invoice class.
|
||||
Refer the method doc for valid values for keys
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$invoices</span> = Invoice::get_all(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Lookup Invoice History"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Lookup Invoice History"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$invoices</span>);</div></div></div></div></body></html>
|
||||
@@ -23,9 +23,8 @@ and payer is retrieved from the invoice details</p></div></div><div class="code"
|
||||
on the Invoice class by passing a valid
|
||||
notification object
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$remindStatus</span> = <span class="hljs-variable">$invoice</span>->remind(<span class="hljs-variable">$notify</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Remind Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$notify</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@ Invoice ID
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$invoice</span> = Invoice::get(<span class="hljs-string">"INV2-W4LC-6QS9-JZ62-VE4P"</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="send-invoice">Send Invoice</h3>
|
||||
<p>Send a legitimate invoice to the payer
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$sendStatus</span> = <span class="hljs-variable">$invoice</span>->send(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Send Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
<span class="hljs-variable">$tokenInfo</span> = <span class="hljs-keyword">new</span> PPOpenIdTokeninfo();
|
||||
<span class="hljs-variable">$tokenInfo</span> = <span class="hljs-variable">$tokenInfo</span>->createFromRefreshToken(<span class="hljs-keyword">array</span>(<span class="hljs-string">'refresh_token'</span> => <span class="hljs-variable">$refreshToken</span>), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,8 @@ to retreive the information. The short lived access token can be retrieved using
|
||||
<span class="hljs-variable">$params</span> = <span class="hljs-keyword">array</span>(<span class="hljs-string">'access_token'</span> => <span class="hljs-variable">$tokenInfo</span>->getAccessToken());
|
||||
<span class="hljs-variable">$userInfo</span> = PPOpenIdUserinfo::getUserinfo(<span class="hljs-variable">$params</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"User Information"</span>, <span class="hljs-string">"User Info"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,8 @@ The user would then able to retrieve the access token by getting the code, which
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Obtain Authorization Code from Code, Client ID and Client Secret</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$accessToken</span> = PPOpenIdTokeninfo::createFromAuthorizationCode(<span class="hljs-keyword">array</span>(<span class="hljs-string">'code'</span> => <span class="hljs-variable">$code</span>), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
ResultPrinter::printError(<span class="hljs-string">"Obtained Access Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'code'</span>], <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Obtained Access Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-variable">$accessToken</span>->getAccessToken(), <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'code'</span>], <span class="hljs-variable">$accessToken</span>);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8,12 +8,8 @@ that contains the web profile ID.</p></div></div><div class="code"><div class="w
|
||||
<span class="hljs-variable">$webProfile</span>->setId(<span class="hljs-variable">$createProfileResponse</span>->getId());
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Execute the delete method</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$webProfile</span>->delete(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
<span class="hljs-keyword">if</span> (is_a(<span class="hljs-variable">$ex</span>, <span class="hljs-string">'\PayPal\Exception\PPConnectionException'</span>)) {
|
||||
<span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> $ex \PayPal\Exception\PPConnectionException */</span>
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
}
|
||||
} <span class="hljs-keyword">catch</span> (\PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Deleted Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$createProfileResponse</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,8 @@ that contains the web profile ID.</p></div></div><div class="code"><div class="w
|
||||
<span class="hljs-variable">$createProfileResponse</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateWebProfile.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>If your request is successful, the API returns a web_profile object response that contains the profile details.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$webProfile</span> = \PayPal\Api\WebProfile::get(<span class="hljs-variable">$createProfileResponse</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
<span class="hljs-keyword">if</span> (is_a(<span class="hljs-variable">$ex</span>, <span class="hljs-string">'\PayPal\Exception\PPConnectionException'</span>)) {
|
||||
<span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> $ex \PayPal\Exception\PPConnectionException */</span>
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
}
|
||||
} <span class="hljs-keyword">catch</span> (\PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$webProfile</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,8 @@
|
||||
static <code>get_list</code> method on the WebProfile class.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$list</span> = \PayPal\Api\WebProfile::get_list(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
<span class="hljs-keyword">if</span> (is_a(<span class="hljs-variable">$ex</span>, <span class="hljs-string">'\PayPal\Exception\PPConnectionException'</span>)) {
|
||||
<span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> $ex \PayPal\Exception\PPConnectionException */</span>
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
}
|
||||
} <span class="hljs-keyword">catch</span> (\PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get List of All Web Profiles"</span>, <span class="hljs-string">"Web Profiles"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-variable">$result</span> = <span class="hljs-string">''</span>;
|
||||
|
||||
@@ -18,11 +18,7 @@ as shown below</p></div></div><div class="code"><div class="wrapper"><span class
|
||||
<span class="hljs-variable">$webProfile</span> = \PayPal\Api\WebProfile::get(<span class="hljs-variable">$webProfile</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
}
|
||||
} <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
<span class="hljs-keyword">if</span> (is_a(<span class="hljs-variable">$ex</span>, <span class="hljs-string">'\PayPal\Exception\PPConnectionException'</span>)) {
|
||||
<span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> $ex \PayPal\Exception\PPConnectionException */</span>
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
}
|
||||
ResultPrinter::printError(<span class="hljs-string">"Partially Updated Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$webProfile</span>->getId(), <span class="hljs-variable">$patches</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,7 @@ create a new web profileId for sample, and return the web profile object.</p></d
|
||||
object</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$updatedWebProfile</span> = \PayPal\Api\WebProfile::get(<span class="hljs-variable">$webProfile</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
}
|
||||
} <span class="hljs-keyword">catch</span> (\<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
<span class="hljs-keyword">if</span> (is_a(<span class="hljs-variable">$ex</span>, <span class="hljs-string">'\PayPal\Exception\PPConnectionException'</span>)) {
|
||||
<span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> $ex \PayPal\Exception\PPConnectionException */</span>
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
}
|
||||
ResultPrinter::printError(<span class="hljs-string">"Updated Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$webProfile</span>->getId(), <span class="hljs-variable">$webProfile</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +1,29 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/AuthorizationCapture</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="payments/AuthorizationCapture"><meta name="groc-project-path" content="payments/AuthorizationCapture.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/AuthorizationCapture.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="authorizationcapture">AuthorizationCapture</h1>
|
||||
<p>This sample code demonstrates how you can capture
|
||||
a previously authorized payment.
|
||||
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/payment
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization">https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Authorization $authorization */</span>
|
||||
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'GetAuthorization.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="capture-payment">Capture Payment</h3>
|
||||
<p>You can capture and process a previously created authorization
|
||||
by invoking the $authorization->capture method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new authorization to get authorization Id
|
||||
createAuthorization defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$authId</span> = <span class="hljs-variable">$authorization</span>->getId();
|
||||
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
|
||||
<span class="hljs-comment">### Capture</span>
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$capture</span>->setId(<span class="hljs-variable">$authId</span>)
|
||||
->setAmount(<span class="hljs-variable">$amt</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Perform a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$getCapture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$capture</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-comment">### Capture</span>
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$capture</span>->setAmount(<span class="hljs-variable">$amt</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Perform a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$getCapture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$capture</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Capture Payment"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$capture</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Capturing an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Captured payment <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$getCapture</span>->getParentPayment(); <span class="hljs-preprocessor">?></span>. Capture Id:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$getCapture</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$getCapture</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Capture Payment"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$getCapture</span>->getId(), <span class="hljs-variable">$capture</span>, <span class="hljs-variable">$getCapture</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$getCapture</span>;</div></div></div></div></body></html>
|
||||
66
sample/doc/payments/AuthorizePayment.html
Normal file
66
sample/doc/payments/AuthorizePayment.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/AuthorizePayment</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="payments/AuthorizePayment"><meta name="groc-project-path" content="payments/AuthorizePayment.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/AuthorizePayment.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="authorize-payment">Authorize Payment</h1>
|
||||
<p>This sample code demonstrates how you can authorize a payment.
|
||||
API used: /v1/payments/authorization
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment">https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Address</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FundingInstrument</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment
|
||||
to correct setting. In this case, it would be 'authorize'</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$addr</span> = <span class="hljs-keyword">new</span> Address();
|
||||
<span class="hljs-variable">$addr</span>->setLine1(<span class="hljs-string">"3909 Witmer Road"</span>)
|
||||
->setLine2(<span class="hljs-string">"Niagara Falls"</span>)
|
||||
->setCity(<span class="hljs-string">"Niagara Falls"</span>)
|
||||
->setState(<span class="hljs-string">"NY"</span>)
|
||||
->setPostalCode(<span class="hljs-string">"14305"</span>)
|
||||
->setCountryCode(<span class="hljs-string">"US"</span>)
|
||||
->setPhone(<span class="hljs-string">"716-298-1822"</span>);
|
||||
|
||||
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> CreditCard();
|
||||
<span class="hljs-variable">$card</span>->setType(<span class="hljs-string">"visa"</span>)
|
||||
->setNumber(<span class="hljs-string">"4417119669820331"</span>)
|
||||
->setExpireMonth(<span class="hljs-string">"11"</span>)
|
||||
->setExpireYear(<span class="hljs-string">"2019"</span>)
|
||||
->setCvv2(<span class="hljs-string">"012"</span>)
|
||||
->setFirstName(<span class="hljs-string">"Joe"</span>)
|
||||
->setLastName(<span class="hljs-string">"Shopper"</span>)
|
||||
->setBillingAddress(<span class="hljs-variable">$addr</span>);
|
||||
|
||||
<span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument();
|
||||
<span class="hljs-variable">$fi</span>->setCreditCard(<span class="hljs-variable">$card</span>);
|
||||
|
||||
<span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
|
||||
<span class="hljs-variable">$payer</span>->setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
|
||||
->setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));
|
||||
|
||||
<span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amount</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
|
||||
<span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
|
||||
<span class="hljs-variable">$transaction</span>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description."</span>);
|
||||
|
||||
<span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Setting intent to authorize creates a payment
|
||||
authorization. Setting it to sale creates actual payment</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span>->setIntent(<span class="hljs-string">"authorize"</span>)
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<p>Create a payment by calling the payment->create() method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">'Authorize a Payment'</span>, <span class="hljs-string">'Authorized Payment'</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">'Authorize a Payment'</span>, <span class="hljs-string">'Authorized Payment'</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
|
||||
|
||||
<span class="hljs-variable">$transactions</span> = <span class="hljs-variable">$payment</span>->getTransactions();
|
||||
<span class="hljs-variable">$relatedResources</span> = <span class="hljs-variable">$transactions</span>[<span class="hljs-number">0</span>]->getRelatedResources();
|
||||
<span class="hljs-variable">$authorization</span> = <span class="hljs-variable">$relatedResources</span>[<span class="hljs-number">0</span>]->getAuthorization();
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$authorization</span>;</div></div></div></div></body></html>
|
||||
@@ -36,7 +36,7 @@ the above types and intent set to 'sale'</p></div></div><div class="code
|
||||
<p>You need to get a permanent refresh token from the authorization code, retrieved from the mobile sdk.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>authorization code from mobile sdk</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationCode</span> = <span class="hljs-string">'EJfRuAqXEE95pdVMmOym_mftTbeJD03RBX-Zjg9pLCAhdLqLeRR6YSKTNsrbQGX7lFoZ3SxwFyxADEZbBOxpn023W9SA0JzSQAy-9eLdON5eDPAyMyKlHyNVS2DqBR2iWVfQGfudbd9MDoRxMEjIZbY'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>correlation id from mobile sdk</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$correlationId</span> = <span class="hljs-string">'123123456'</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Exchange authorization_code for long living refresh token. You should store
|
||||
it in a database for later use</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$refreshToken</span> = FuturePayment::getRefreshToken(<span class="hljs-variable">$authorizationCode</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Update the access token in apiContext</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$payment</span>->updateAccessToken(<span class="hljs-variable">$refreshToken</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-future-payment">Create Future Payment</h3>
|
||||
it in a database for later use</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$refreshToken</span> = FuturePayment::getRefreshToken(<span class="hljs-variable">$authorizationCode</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Update the access token in apiContext</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$payment</span>->updateAccessToken(<span class="hljs-variable">$refreshToken</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-future-payment">Create Future Payment</h3>
|
||||
<p>Create a payment by calling the 'create' method
|
||||
passing it a valid apiContext.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)
|
||||
@@ -45,23 +45,11 @@ url to which the buyer must be redirected to
|
||||
for payment approval
|
||||
Please note that currently future payments works only with PayPal as a funding instrument.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>, <span class="hljs-variable">$correlationId</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Future Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Future payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Future Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>
|
||||
@@ -66,32 +66,22 @@ payment - what is the payment for and who
|
||||
is fulfilling it. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
|
||||
<span class="hljs-variable">$transaction</span>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>)
|
||||
->setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent set to sale 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
|
||||
<span class="hljs-variable">$payment</span>->setIntent(<span class="hljs-string">"sale"</span>)
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<p>Create a payment by calling the payment->create() method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">'Create Payment Using Credit Card'</span>, <span class="hljs-string">'Payment'</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">'Create Payment Using Credit Card'</span>, <span class="hljs-string">'Payment'</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>
|
||||
@@ -17,14 +17,14 @@ to 'paypal'.</p></div></div><div class="code"><div class="wrapper"><span
|
||||
<p>(Optional) Lets you specify item wise
|
||||
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
|
||||
<span class="hljs-variable">$item1</span>->setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setPrice(<span class="hljs-string">'7.50'</span>);
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setPrice(<span class="hljs-string">'7.50'</span>);
|
||||
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
|
||||
<span class="hljs-variable">$item2</span>->setName(<span class="hljs-string">'Granola bars'</span>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</span>);
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</span>);
|
||||
|
||||
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
|
||||
<span class="hljs-variable">$itemList</span>->setItems(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$item1</span>, <span class="hljs-variable">$item2</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-payment-details">Additional payment details</h3>
|
||||
@@ -32,51 +32,52 @@ information</p></div></div><div class="code"><div class="wrapper"><span class="h
|
||||
payment information such as tax, shipping
|
||||
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
|
||||
<span class="hljs-variable">$details</span>->setShipping(<span class="hljs-string">'1.20'</span>)
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
<p>Lets you specify a payment amount.
|
||||
You can also specify additional details
|
||||
such as shipping, tax.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amount</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"20.00"</span>)
|
||||
->setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||
->setTotal(<span class="hljs-string">"20.00"</span>)
|
||||
->setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><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. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
|
||||
<span class="hljs-variable">$transaction</span>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>)
|
||||
->setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><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="hljs-variable">$baseUrl</span> = getBaseUrl();
|
||||
<span class="hljs-variable">$redirectUrls</span> = <span class="hljs-keyword">new</span> RedirectUrls();
|
||||
<span class="hljs-variable">$redirectUrls</span>->setReturnUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=true"</span>)
|
||||
->setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
->setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent set to 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
|
||||
<span class="hljs-variable">$payment</span>->setIntent(<span class="hljs-string">"sale"</span>)
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<p>Create a payment by calling the 'create' method
|
||||
passing it a valid apiContext.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the state 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="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Created Payment Using PayPal. Please visit the URL to Approve."</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-redirect-url">Get redirect url</h3>
|
||||
<p>The API response provides the url that you must redirect
|
||||
the buyer to. Retrieve the url from the $payment->getLinks()
|
||||
method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$payment</span>->getLinks() <span class="hljs-keyword">as</span> <span class="hljs-variable">$link</span>) {
|
||||
<span class="hljs-keyword">if</span>(<span class="hljs-variable">$link</span>->getRel() == <span class="hljs-string">'approval_url'</span>) {
|
||||
<span class="hljs-variable">$redirectUrl</span> = <span class="hljs-variable">$link</span>->getHref();
|
||||
<span class="hljs-keyword">break</span>;
|
||||
}
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="redirect-buyer-to-paypal-website">Redirect buyer to PayPal website</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$redirectUrl</span>)) {
|
||||
header(<span class="hljs-string">"Location: $redirectUrl"</span>);
|
||||
<span class="hljs-keyword">exit</span>;
|
||||
}</div></div></div></div></body></html>
|
||||
method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$payment</span>->getLinks() <span class="hljs-keyword">as</span> <span class="hljs-variable">$link</span>) {
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-variable">$link</span>->getRel() == <span class="hljs-string">'approval_url'</span>) {
|
||||
<span class="hljs-variable">$approvalUrl</span> = <span class="hljs-variable">$link</span>->getHref();
|
||||
<span class="hljs-keyword">break</span>;
|
||||
}
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Created Payment Using PayPal. Please visit the URL to Approve."</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-string">"<a href='$approvalUrl' >$approvalUrl</a>"</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>
|
||||
@@ -1,7 +1,8 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/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="payments/CreatePaymentUsingSavedCard"><meta name="groc-project-path" content="payments/CreatePaymentUsingSavedCard.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/CreatePaymentUsingSavedCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><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 stored credit card token.
|
||||
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> CreditCard $card */</span>
|
||||
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../vault/CreateCreditCard.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
|
||||
@@ -10,10 +11,11 @@ API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrap
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FundingInstrument</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="credit-card-token">Credit card token</h3>
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;</div></div></div><div class="segment"><div class="comments "><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="hljs-variable">$creditCardToken</span> = <span class="hljs-keyword">new</span> CreditCardToken();
|
||||
<span class="hljs-variable">$creditCardToken</span>->setCreditCardId(<span class="hljs-string">'CARD-17M96700G1952584EKRCTV5Y'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||
<span class="hljs-variable">$creditCardToken</span>->setCreditCardId(<span class="hljs-variable">$card</span>->getId());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||
<p>A resource representing a Payer's funding instrument.
|
||||
For stored credit card payments, set the CreditCardToken
|
||||
field on this object.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument();
|
||||
@@ -22,18 +24,18 @@ field on this object.</p></div></div><div class="code"><div class="wrapper"><spa
|
||||
For stored credit card payments, set payment method
|
||||
to 'credit_card'.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
|
||||
<span class="hljs-variable">$payer</span>->setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
|
||||
->setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="itemized-information">Itemized information</h3>
|
||||
->setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="itemized-information">Itemized information</h3>
|
||||
<p>(Optional) Lets you specify item wise
|
||||
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
|
||||
<span class="hljs-variable">$item1</span>->setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setPrice(<span class="hljs-string">'7.50'</span>);
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setPrice(<span class="hljs-string">'7.50'</span>);
|
||||
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
|
||||
<span class="hljs-variable">$item2</span>->setName(<span class="hljs-string">'Granola bars'</span>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</span>);
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</span>);
|
||||
|
||||
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
|
||||
<span class="hljs-variable">$itemList</span>->setItems(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$item1</span>, <span class="hljs-variable">$item2</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-payment-details">Additional payment details</h3>
|
||||
@@ -41,46 +43,36 @@ information</p></div></div><div class="code"><div class="wrapper"><span class="h
|
||||
payment information such as tax, shipping
|
||||
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
|
||||
<span class="hljs-variable">$details</span>->setShipping(<span class="hljs-string">'1.20'</span>)
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
<p>Lets you specify a payment amount.
|
||||
You can also specify additional details
|
||||
such as shipping, tax.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amount</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"20.00"</span>)
|
||||
->setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||
->setTotal(<span class="hljs-string">"20.00"</span>)
|
||||
->setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><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. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
|
||||
<span class="hljs-variable">$transaction</span>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>)
|
||||
->setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent set to 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
|
||||
<span class="hljs-variable">$payment</span>->setIntent(<span class="hljs-string">"sale"</span>)
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<p>Create a payment by calling the 'create' method
|
||||
passing it a valid apiContext.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$payment</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Create Payment using Saved Card"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Saved Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Create Payment using Saved Card"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>
|
||||
@@ -20,12 +20,8 @@ when the user is redirected from paypal back to your site</p></div></div><div cl
|
||||
|
||||
<span class="hljs-comment">//Execute the payment</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$result</span> = <span class="hljs-variable">$payment</span>->execute(<span class="hljs-variable">$execution</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"<html><body><pre>"</span>;
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-variable">$result</span>->toJSON(<span class="hljs-number">128</span>);
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"</pre><a href='../index.html'>Back</a></body></html>"</span>;
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Executed Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$execution</span>, <span class="hljs-variable">$result</span>);
|
||||
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"<html><body><h1>"</span>;
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"User cancelled payment."</span>;
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"</h1><a href='../index.html'>Back</a></body></html>"</span>;
|
||||
ResultPrinter::printResult(<span class="hljs-string">"User Cancelled the Approval"</span>, <span class="hljs-keyword">null</span>);
|
||||
}</div></div></div></div></body></html>
|
||||
@@ -1,31 +1,20 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/GetAuthorization</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="payments/GetAuthorization"><meta name="groc-project-path" content="payments/GetAuthorization.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/GetAuthorization.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="getauthorization">GetAuthorization</h1>
|
||||
<p>This sample code demonstrates how you can get details
|
||||
of an authorized payment.
|
||||
API used: /v1/payments/authorization/<$authorizationId></p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/authorization/<$authorizationId></p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Authorization $authorization */</span>
|
||||
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="getauthorization">GetAuthorization</h3>
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="getauthorization">GetAuthorization</h3>
|
||||
<p>You can retrieve info about an Authorization
|
||||
by invoking the Authorization::get method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the authorization state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>create a authorization to get authorization Id
|
||||
createAuthorization is defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieve the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
The return object contains the authorization state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieve the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$result</span> = Authorization::get(<span class="hljs-variable">$authorization</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Retrieved Authorization:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$authorization</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$authorization</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Get Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$authorization</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$result</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$authorization</span>;</div></div></div></div></body></html>
|
||||
@@ -1,47 +1,18 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/GetCapture</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="payments/GetCapture"><meta name="groc-project-path" content="payments/GetCapture.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/GetCapture.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="getcapture">GetCapture</h1>
|
||||
<p>This sample code demonstrates how you can lookup the details
|
||||
of a captured payment.
|
||||
API used: /v1/payments/capture/<$captureId></p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/capture/<$captureId></p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Capture $request */</span>
|
||||
<span class="hljs-variable">$request</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizationCapture.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-a-mock-capture">Create a mock Capture</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>create a mock authorization to get authorization Id
|
||||
createAuthorization is defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-comment">### Capture</span>
|
||||
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$captureInfo</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$captureInfo</span>->setId(<span class="hljs-variable">$authId</span>)
|
||||
->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$captureInfo</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-capture-details">Retrieve Capture details</h3>
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-capture-details">Retrieve Capture details</h3>
|
||||
<p>You can look up a capture by invoking the Capture::get method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$capture</span> = Capture::get(<span class="hljs-variable">$capture</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$capture</span> = Capture::get(<span class="hljs-variable">$request</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get Captured Payment"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$request</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a capture</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Capture Id:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$capture</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$capture</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Get Captured Payment"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$capture</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$capture</span>);</div></div></div></div></body></html>
|
||||
@@ -5,29 +5,22 @@ 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="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Payment $createdPayment */</span>
|
||||
<span class="hljs-variable">$createdPayment</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePayment.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
|
||||
|
||||
<span class="hljs-variable">$paymentId</span> = <span class="hljs-string">"PAY-2AH507590P6615624KRCTUSY"</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
<span class="hljs-variable">$paymentId</span> = <span class="hljs-variable">$createdPayment</span>->getId();</div></div></div><div class="segment"><div class="comments "><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
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$paymentId</span>;<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Get Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$payment</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>
|
||||
@@ -5,7 +5,7 @@ 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="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePayment.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><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,
|
||||
@@ -13,20 +13,13 @@ and pass a Map object that contains
|
||||
query parameters for paginations and filtering.
|
||||
Refer the method doc for valid values for keys
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$payments</span> = Payment::all(<span class="hljs-keyword">array</span>(<span class="hljs-string">'count'</span> => <span class="hljs-number">10</span>, <span class="hljs-string">'start_index'</span> => <span class="hljs-number">5</span>), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
|
||||
<span class="hljs-variable">$params</span> = <span class="hljs-keyword">array</span>(<span class="hljs-string">'count'</span> => <span class="hljs-number">10</span>, <span class="hljs-string">'start_index'</span> => <span class="hljs-number">5</span>);
|
||||
|
||||
<span class="hljs-variable">$payments</span> = Payment::all(<span class="hljs-variable">$params</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"List Payments"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup payment history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payments</span>->getCount(); <span class="hljs-preprocessor">?></span> matching payments </div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payments</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"List Payments"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</span>, <span class="hljs-variable">$payments</span>);</div></div></div></div></body></html>
|
||||
@@ -1,37 +1,23 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/Reauthorization</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="payments/Reauthorization"><meta name="groc-project-path" content="payments/Reauthorization.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/Reauthorization.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="reauthorization-sample">Reauthorization Sample</h2>
|
||||
<p>This sample code demonstrates how you can reauthorize a PayPal
|
||||
account payment.
|
||||
API used: v1/payments/authorization/{authorization_id}/reauthorize</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: v1/payments/authorization/{authorization_id}/reauthorize</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Authorization $authorization */</span>
|
||||
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="reauthorization">Reauthorization</h3>
|
||||
<p>Reauthorization is available only for PayPal account payments
|
||||
and not for credit card payments.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>You can reauthorize a payment only once 4 to 29
|
||||
days after the 3-day honor period for the original authorization
|
||||
has expired.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="lookup-authorization-using-the-authorization-id">Lookup authorization using the authorization id</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-string">'7GH53639GA425732B'</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amount</span>->setCurrency(<span class="hljs-string">"USD"</span>);
|
||||
<span class="hljs-variable">$amount</span>->setTotal(<span class="hljs-string">"1.00"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="reauthorize-with-amount-being-reauthorized">Reauthorize with amount being reauthorized</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span>->setAmount(<span class="hljs-variable">$amount</span>);
|
||||
<span class="hljs-variable">$reauthorization</span> = <span class="hljs-variable">$authorization</span>->reauthorize(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amount</span>->setCurrency(<span class="hljs-string">"USD"</span>);
|
||||
<span class="hljs-variable">$amount</span>->setTotal(<span class="hljs-string">"1.00"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="reauthorize-with-amount-being-reauthorized">Reauthorize with amount being reauthorized</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span>->setAmount(<span class="hljs-variable">$amount</span>);
|
||||
|
||||
<span class="hljs-variable">$reAuthorization</span> = <span class="hljs-variable">$authorization</span>->reauthorize(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Reauthorize Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Reauthorize a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Reauthorization Id:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$reauthorization</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre>
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$reauthorization</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span>
|
||||
</pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Reauthorize Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$authorization</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$reAuthorization</span>);</div></div></div></div></body></html>
|
||||
@@ -1,52 +1,24 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/RefundCapture</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="payments/RefundCapture"><meta name="groc-project-path" content="payments/RefundCapture.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/RefundCapture.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="refund-capture-sample">Refund Capture Sample</h1>
|
||||
<p>This sample code demonstrates how you can
|
||||
process a refund on a Captured transaction.
|
||||
API used: /v1/payments/capture/{<captureID>}/refund</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/capture/{<captureID>}/refund</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Capture $capture */</span>
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizationCapture.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Rest</span>\<span class="hljs-title">ApiContext</span>;
|
||||
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a mock authorization to get authorization Id</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="capture">Capture</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper">
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$captureInfo</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$captureInfo</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$captureInfo</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
<p>Create a refund object indicating
|
||||
refund amount and call the refund method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund();
|
||||
<span class="hljs-variable">$refund</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new
|
||||
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext();
|
||||
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>);
|
||||
|
||||
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>->refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>->refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a captured payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refund Capture:</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$captureRefund</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$captureRefund</span>->getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$captureRefund</span>);</div></div></div></div></body></html>
|
||||
@@ -1,28 +1,18 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/VoidAuthorization</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="payments/VoidAuthorization"><meta name="groc-project-path" content="payments/VoidAuthorization.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/VoidAuthorization.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="voidauthorization">VoidAuthorization</h1>
|
||||
<p>This sample code demonstrates how you can
|
||||
void an authorized payment.
|
||||
API used: /v1/payments/authorization/<{authorizationid}>/void"</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/authorization/<{authorizationid}>/void"</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Authorization $authorization */</span>
|
||||
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="voidauthorization">VoidAuthorization</h3>
|
||||
<p>You can void a previously authorized payment
|
||||
by invoking the $authorization->void method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>create an authorization to get authorization Id
|
||||
createAuthorization is defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Void the authorization </p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$voidedAuth</span> = <span class="hljs-variable">$authorization</span>->void(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authorization</span>->getId(), <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Void the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$voidedAuth</span> = <span class="hljs-variable">$authorization</span>->void(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Void Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Void an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Voided authorization
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$voidedAuth</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Void Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$voidedAuth</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$voidedAuth</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$voidedAuth</span>;</div></div></div></div></body></html>
|
||||
@@ -2,27 +2,23 @@
|
||||
<p>Sale transactions are nothing but completed payments.
|
||||
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="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/sale/{sale-id}</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Payment $payment */</span>
|
||||
<span class="hljs-variable">$payment</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../payments/CreatePayment.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Sale</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-sale-from-created-payment">Get Sale From Created Payment</h3>
|
||||
<p>You can retrieve the sale Id from Related Resources for each transactions.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transactions</span> = <span class="hljs-variable">$payment</span>->getTransactions();
|
||||
<span class="hljs-variable">$relatedResources</span> = <span class="hljs-variable">$transactions</span>[<span class="hljs-number">0</span>]->getRelatedResources();
|
||||
<span class="hljs-variable">$sale</span> = <span class="hljs-variable">$relatedResources</span>[<span class="hljs-number">0</span>]->getSale();
|
||||
<span class="hljs-variable">$saleId</span> = <span class="hljs-variable">$sale</span>->getId();
|
||||
|
||||
<span class="hljs-variable">$saleId</span> = <span class="hljs-string">'3RM92092UW5126232'</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> { </div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><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="hljs-variable">$sale</span> = Sale::get(<span class="hljs-variable">$saleId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
transaction from your payment resource.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$sale</span> = Sale::get(<span class="hljs-variable">$saleId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Look Up A Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$sale</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a sale</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving sale id: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$saleId</span>;<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$sale</span>->toJSON(<span class="hljs-number">128</span>)<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Look Up A Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$sale</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$sale</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$sale</span>;</div></div></div></div></body></html>
|
||||
@@ -2,7 +2,10 @@
|
||||
<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="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
API used: /v1/payments/sale/{sale-id}/refund</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Sale $sale */</span>
|
||||
<span class="hljs-variable">$sale</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'GetSale.php'</span>;
|
||||
<span class="hljs-variable">$saleId</span> = <span class="hljs-variable">$sale</span>->getId();
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Sale</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-amount">Refund amount</h3>
|
||||
@@ -10,29 +13,20 @@ API used: /v1/payments/sale/{sale-id}/refund</p></div></div><div class="code"><d
|
||||
and refunded fee (to Payee). Use the $amt->details
|
||||
field to mention fees refund details.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setTotal(<span class="hljs-string">'0.01'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-object">Refund object</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund();
|
||||
<span class="hljs-variable">$refund</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-variable">$saleId</span> = <span class="hljs-string">'3RM92092UW5126232'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="sale">Sale</h3>
|
||||
->setTotal(<span class="hljs-string">'0.01'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-object">Refund object</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund();
|
||||
<span class="hljs-variable">$refund</span>->setAmount(<span class="hljs-variable">$amt</span>);</div></div></div><div class="segment"><div class="comments "><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="hljs-variable">$sale</span> = <span class="hljs-keyword">new</span> Sale();
|
||||
<span class="hljs-variable">$sale</span>->setId(<span class="hljs-variable">$saleId</span>);
|
||||
<span class="hljs-keyword">try</span> { </div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Refund the sale
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$sale</span>->refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new
|
||||
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Refund the sale
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$refundedSale</span> = <span class="hljs-variable">$sale</span>->refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Refund Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$refundedSale</span>->getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a sale</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refunding sale id: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$saleId</span>;<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$sale</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Refund Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$refundedSale</span>->getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$refundedSale</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$refundedSale</span>;</div></div></div></div></body></html>
|
||||
@@ -7,31 +7,23 @@ API used: POST /v1/vault/credit-card</p></div></div><div class="code"><div class
|
||||
<p>A resource representing a credit card that is
|
||||
to be stored with PayPal.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> CreditCard();
|
||||
<span class="hljs-variable">$card</span>->setType(<span class="hljs-string">"visa"</span>)
|
||||
->setNumber(<span class="hljs-string">"4417119669820331"</span>)
|
||||
->setExpireMonth(<span class="hljs-string">"11"</span>)
|
||||
->setExpireYear(<span class="hljs-string">"2019"</span>)
|
||||
->setCvv2(<span class="hljs-string">"012"</span>)
|
||||
->setFirstName(<span class="hljs-string">"Joe"</span>)
|
||||
->setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="save-card">Save card</h3>
|
||||
->setNumber(<span class="hljs-string">"4417119669820331"</span>)
|
||||
->setExpireMonth(<span class="hljs-string">"11"</span>)
|
||||
->setExpireYear(<span class="hljs-string">"2019"</span>)
|
||||
->setCvv2(<span class="hljs-string">"012"</span>)
|
||||
->setFirstName(<span class="hljs-string">"Joe"</span>)
|
||||
->setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$card</span>;</div></div></div><div class="segment"><div class="comments "><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 future payments.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$card</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$card</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Create Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Save a credit card</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Saved a <span class="hljs-keyword">new</span> credit card with id: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$card</span>->getId();<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$card</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Create Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$card</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>
|
||||
@@ -2,44 +2,18 @@
|
||||
<p>This sample code demonstrate how you can
|
||||
delete a saved credit card.
|
||||
API used: /v1/vault/credit-card/{<creditCardId>}
|
||||
NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Store a mock card that can be deleted later.</p>
|
||||
<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="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> CreditCard();
|
||||
<span class="hljs-variable">$card</span>->setType(<span class="hljs-string">"visa"</span>)
|
||||
->setNumber(<span class="hljs-string">"4417119669820331"</span>)
|
||||
->setExpireMonth(<span class="hljs-string">"11"</span>)
|
||||
->setExpireYear(<span class="hljs-string">"2019"</span>)
|
||||
->setCvv2(<span class="hljs-string">"012"</span>)
|
||||
->setFirstName(<span class="hljs-string">"Joe"</span>)
|
||||
->setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><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 later.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$card</span> = <span class="hljs-variable">$card</span>->create(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> CreditCard $card */</span>
|
||||
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-card">Delete Card</h3>
|
||||
<p>Lookup and delete a saved credit card.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$creditCard</span> = CreditCard::get(<span class="hljs-variable">$card</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
<span class="hljs-variable">$creditCard</span>->delete(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$creditCard</span> = CreditCard::get(<span class="hljs-variable">$card</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-variable">$creditCard</span>->delete(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Delete a saved credit card</title>
|
||||
</head>
|
||||
<body>
|
||||
<p> Credit Card deleted Successfully</p>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$creditCard</span>);</div></div></div></div></body></html>
|
||||
@@ -3,25 +3,18 @@
|
||||
retrieve previously saved CreditCards.
|
||||
API called: '/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="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;</div></div></div><div class="segment"><div class="comments "><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="hljs-variable">$cardId</span> = <span class="hljs-string">"CARD-44D10970C24287906KRCTWNI"</span>;
|
||||
the process of retrieving a saved CreditCard</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> CreditCard $card */</span>
|
||||
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;
|
||||
|
||||
<span class="hljs-comment">/// ### Retrieve card</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$card</span> = CreditCard::get(<span class="hljs-variable">$cardId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable">$card</span> = CreditCard::get(<span class="hljs-variable">$card</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
ResultPrinter::printError(<span class="hljs-string">"Get Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a saved credit card</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving saved credit card: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$cardId</span>;<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$card</span>->toJSON(<span class="hljs-number">128</span>);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Get Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$card</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>
|
||||
@@ -22,6 +22,19 @@
|
||||
overflow-y: auto;
|
||||
overflow-wrap: normal;
|
||||
}
|
||||
pre.error {
|
||||
border-color: red;
|
||||
color: red;
|
||||
overflow-y: visible;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
.panel-default>.panel-heading.error {
|
||||
background-color: red;
|
||||
color: white;
|
||||
}
|
||||
h1.error, h2.error, h3.error, h4.error, h5.error {
|
||||
color: red;
|
||||
}
|
||||
.panel-default>.panel-heading {
|
||||
color: #FFF;
|
||||
background-color: #428bca;
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Get sale details</h5></div>
|
||||
<div class="col-md-9 "><h5>Get Sale details</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="sale/GetSale.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/sale/GetSale.html" class="btn btn-default pull-right" >Source <i class="fa fa-file-code-o"></i></a>
|
||||
@@ -124,7 +124,7 @@
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Refund a payment</h5></div>
|
||||
<div class="col-md-9 "><h5>Refund a Sale</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="sale/RefundSale.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/sale/RefundSale.html" class="btn btn-default pull-right" >Source <i class="fa fa-file-code-o"></i></a>
|
||||
@@ -275,6 +275,15 @@
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Authorize Payment</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="payments/AuthorizePayment.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/AuthorizePayment.html" class="btn btn-default pull-right" >Source <i class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Get details of an authorized payment</h5></div>
|
||||
@@ -293,6 +302,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Get details of a captured payment</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="payments/GetCapture.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/GetCapture.html" class="btn btn-default pull-right" >Source <i class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Void an authorized payment</h5></div>
|
||||
@@ -311,15 +329,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Get details of a captured payment</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="payments/GetCapture.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/payments/GetCapture.html" class="btn btn-default pull-right" >Source <i class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Refund captured payment</h5></div>
|
||||
|
||||
@@ -37,9 +37,8 @@ try {
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$cancelStatus = $invoice->cancel($notify, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Cancel Invoice", "Invoice", null, $notify, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,9 +101,8 @@ try {
|
||||
// Create an invoice by calling the invoice->create() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
$invoice->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Invoice Creation", "Invoice", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@ $invoiceId = "INV2-W4LC-6QS9-JZ62-VE4P";
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoiceId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@ try {
|
||||
// Refer the method doc for valid values for keys
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$invoices = Invoice::get_all($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Lookup Invoice History", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices);
|
||||
|
||||
@@ -35,9 +35,8 @@ try {
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$remindStatus = $invoice->remind($notify, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Remind Invoice", "Invoice", null, $notify, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,8 @@ try {
|
||||
// Send a legitimate invoice to the payer
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
$sendStatus = $invoice->send($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printResult("Send Invoice", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,8 @@ try {
|
||||
$tokenInfo = new PPOpenIdTokeninfo();
|
||||
$tokenInfo = $tokenInfo->createFromRefreshToken(array('refresh_token' => $refreshToken), $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Obtained Access Token From Refresh Token", "Access Token", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,8 @@ try {
|
||||
$params = array('access_token' => $tokenInfo->getAccessToken());
|
||||
$userInfo = PPOpenIdUserinfo::getUserinfo($params, $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("User Information", "User Info", null, $params, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
// Obtain Authorization Code from Code, Client ID and Client Secret
|
||||
$accessToken = PPOpenIdTokeninfo::createFromAuthorizationCode(array('code' => $code), null, null, $apiContext);
|
||||
} catch (PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
ResultPrinter::printError("Obtained Access Token", "Access Token", null, $_GET['code'], $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $_GET['code'], $accessToken);
|
||||
|
||||
@@ -41,7 +41,9 @@ $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
|
||||
// Parameters for flow configuration.
|
||||
->setFlowConfig($flowConfig)
|
||||
// Parameters for style and presentation.
|
||||
->setPresentation($presentation);
|
||||
->setPresentation($presentation)
|
||||
// Parameters for input field customization.
|
||||
->setInputFields($inputFields);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $webProfile;
|
||||
@@ -49,12 +51,8 @@ $request = clone $webProfile;
|
||||
try {
|
||||
// Use this call to create a profile.
|
||||
$createProfileResponse = $webProfile->create($apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
} catch (\PayPal\Exception\PPConnectionException $ex) {
|
||||
ResultPrinter::printError("Created Web Profile", "Web Profile", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,8 @@ $webProfile->setId($createProfileResponse->getId());
|
||||
try {
|
||||
// Execute the delete method
|
||||
$webProfile->delete($apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
} catch (\PayPal\Exception\PPConnectionException $ex) {
|
||||
ResultPrinter::printError("Deleted Web Profile", "Web Profile", $createProfileResponse->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,8 @@ $createProfileResponse = require 'CreateWebProfile.php';
|
||||
try {
|
||||
// If your request is successful, the API returns a web_profile object response that contains the profile details.
|
||||
$webProfile = \PayPal\Api\WebProfile::get($createProfileResponse->getId(), $apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
} catch (\PayPal\Exception\PPConnectionException $ex) {
|
||||
ResultPrinter::printError("Get Web Profile", "Web Profile", $webProfile->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,8 @@ $apiContext = require __DIR__ . '/../bootstrap.php';
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$list = \PayPal\Api\WebProfile::get_list($apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
} catch (\PayPal\Exception\PPConnectionException $ex) {
|
||||
ResultPrinter::printError("Get List of All Web Profiles", "Web Profiles", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
$result = '';
|
||||
|
||||
@@ -37,11 +37,7 @@ try {
|
||||
$webProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
ResultPrinter::printError("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,7 @@ try {
|
||||
$updatedWebProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
ResultPrinter::printError("Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
// This sample code demonstrates how you can capture
|
||||
// a previously authorized payment.
|
||||
// API used: /v1/payments/payment
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'GetAuthorization.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Authorization;
|
||||
@@ -15,40 +17,23 @@ use PayPal\Api\Authorization;
|
||||
// by invoking the $authorization->capture method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
// Create a new authorization to get authorization Id
|
||||
// createAuthorization defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
$authId = $authorization->getId();
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setId($authId)
|
||||
->setAmount($amt);
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setAmount($amt);
|
||||
|
||||
// Lookup the authorization.
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
// Perform a capture
|
||||
$getCapture = $authorization->capture($capture, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Perform a capture
|
||||
$getCapture = $authorization->capture($capture, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Capture Payment", "Authorization", null, $capture, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Capturing an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id:
|
||||
<?php echo $getCapture->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $getCapture->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Capture Payment", "Authorization", $getCapture->getId(), $capture, $getCapture);
|
||||
|
||||
return $getCapture;
|
||||
|
||||
81
sample/payments/AuthorizePayment.php
Normal file
81
sample/payments/AuthorizePayment.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
// # Authorize Payment
|
||||
// This sample code demonstrates how you can authorize a payment.
|
||||
// API used: /v1/payments/authorization
|
||||
// https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
// The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment
|
||||
// to correct setting. In this case, it would be 'authorize'
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road")
|
||||
->setLine2("Niagara Falls")
|
||||
->setCity("Niagara Falls")
|
||||
->setState("NY")
|
||||
->setPostalCode("14305")
|
||||
->setCountryCode("US")
|
||||
->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper")
|
||||
->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("Payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
|
||||
// Setting intent to authorize creates a payment
|
||||
// authorization. Setting it to sale creates actual payment
|
||||
$payment->setIntent("authorize")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by calling the payment->create() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the state.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment);
|
||||
|
||||
$transactions = $payment->getTransactions();
|
||||
$relatedResources = $transactions[0]->getRelatedResources();
|
||||
$authorization = $relatedResources[0]->getAuthorization();
|
||||
|
||||
return $authorization;
|
||||
@@ -70,6 +70,9 @@ try {
|
||||
// Update the access token in apiContext
|
||||
$payment->updateAccessToken($refreshToken, $apiContext);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ### Create Future Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
// passing it a valid apiContext.
|
||||
@@ -80,23 +83,11 @@ try {
|
||||
// Please note that currently future payments works only with PayPal as a funding instrument.
|
||||
$payment->create($apiContext, $correlationId);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Future Payment", "Payment", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Future payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Future Payment", "Payment", $payment->getId(), $request, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -92,7 +92,8 @@ $amount->setCurrency("USD")
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
->setDescription("Payment description")
|
||||
->setInvoiceNumber(uniqid());
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
@@ -102,28 +103,20 @@ $payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by calling the payment->create() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the state.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError('Create Payment Using Credit Card', 'Payment', null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -27,14 +27,14 @@ $payer->setPaymentMethod("paypal");
|
||||
// information
|
||||
$item1 = new Item();
|
||||
$item1->setName('Ground Coffee 40 oz')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
$item2 = new Item();
|
||||
$item2->setName('Granola bars')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
|
||||
$itemList = new ItemList();
|
||||
$itemList->setItems(array($item1, $item2));
|
||||
@@ -45,8 +45,8 @@ $itemList->setItems(array($item1, $item2));
|
||||
// charges etc.
|
||||
$details = new Details();
|
||||
$details->setShipping('1.20')
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
|
||||
// ### Amount
|
||||
// Lets you specify a payment amount.
|
||||
@@ -54,8 +54,8 @@ $details->setShipping('1.20')
|
||||
// such as shipping, tax.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -63,8 +63,9 @@ $amount->setCurrency("USD")
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description")
|
||||
->setInvoiceNumber(uniqid());
|
||||
|
||||
// ### Redirect urls
|
||||
// Set the urls that the buyer must be redirected to after
|
||||
@@ -72,16 +73,20 @@ $transaction->setAmount($amount)
|
||||
$baseUrl = getBaseUrl();
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
@@ -91,26 +96,23 @@ $payment->setIntent("sale")
|
||||
// url to which the buyer must be redirected to
|
||||
// for payment approval
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$payment->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Get redirect url
|
||||
// The API response provides the url that you must redirect
|
||||
// the buyer to. Retrieve the url from the $payment->getLinks()
|
||||
// method
|
||||
foreach($payment->getLinks() as $link) {
|
||||
if($link->getRel() == 'approval_url') {
|
||||
$redirectUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
foreach ($payment->getLinks() as $link) {
|
||||
if ($link->getRel() == 'approval_url') {
|
||||
$approvalUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ### Redirect buyer to PayPal website
|
||||
if(isset($redirectUrl)) {
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
// Payment using a previously stored credit card token.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var CreditCard $card */
|
||||
$card = require __DIR__ . '/../vault/CreateCreditCard.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Details;
|
||||
use PayPal\Api\Item;
|
||||
@@ -15,12 +16,13 @@ use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\CreditCard;
|
||||
|
||||
// ### Credit card token
|
||||
// Saved credit card id from a previous call to
|
||||
// CreateCreditCard.php
|
||||
$creditCardToken = new CreditCardToken();
|
||||
$creditCardToken->setCreditCardId('CARD-17M96700G1952584EKRCTV5Y');
|
||||
$creditCardToken->setCreditCardId($card->getId());
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
@@ -35,21 +37,21 @@ $fi->setCreditCardToken($creditCardToken);
|
||||
// to 'credit_card'.
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
// ### Itemized information
|
||||
// (Optional) Lets you specify item wise
|
||||
// information
|
||||
$item1 = new Item();
|
||||
$item1->setName('Ground Coffee 40 oz')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
$item2 = new Item();
|
||||
$item2->setName('Granola bars')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
|
||||
$itemList = new ItemList();
|
||||
$itemList->setItems(array($item1, $item2));
|
||||
@@ -60,8 +62,8 @@ $itemList->setItems(array($item1, $item2));
|
||||
// charges etc.
|
||||
$details = new Details();
|
||||
$details->setShipping('1.20')
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
|
||||
// ### Amount
|
||||
// Lets you specify a payment amount.
|
||||
@@ -69,8 +71,8 @@ $details->setShipping('1.20')
|
||||
// such as shipping, tax.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -78,16 +80,21 @@ $amount->setCurrency("USD")
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description")
|
||||
->setInvoiceNumber(uniqid());
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ###Create Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
@@ -95,23 +102,12 @@ $payment->setIntent("sale")
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the state.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$payment->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Saved Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment);
|
||||
|
||||
return $card;
|
||||
|
||||
@@ -31,12 +31,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$result = $payment->execute($execution, $apiContext);
|
||||
|
||||
echo "<html><body><pre>";
|
||||
echo $result->toJSON(128);
|
||||
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||
ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result);
|
||||
|
||||
} else {
|
||||
echo "<html><body><h1>";
|
||||
echo "User cancelled payment.";
|
||||
echo "</h1><a href='../index.html'>Back</a></body></html>";
|
||||
ResultPrinter::printResult("User Cancelled the Approval", null);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
// of an authorized payment.
|
||||
// API used: /v1/payments/authorization/<$authorizationId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'AuthorizePayment.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
// ### GetAuthorization
|
||||
// You can retrieve info about an Authorization
|
||||
@@ -16,28 +17,13 @@ use PayPal\Api\Authorization;
|
||||
// The return object contains the authorization state.
|
||||
|
||||
try {
|
||||
// create a authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Retrieve the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Retrieve the authorization
|
||||
$result = Authorization::get($authorization->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Retrieved Authorization:
|
||||
<?php echo $authorization->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $authorization->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result);
|
||||
|
||||
return $authorization;
|
||||
|
||||
@@ -4,61 +4,21 @@
|
||||
// of a captured payment.
|
||||
// API used: /v1/payments/capture/<$captureId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Capture $request */
|
||||
$request = require 'AuthorizationCapture.php';
|
||||
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
|
||||
// ### Create a mock Capture
|
||||
try {
|
||||
// create a mock authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
### Capture
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// Create a capture
|
||||
$captureInfo = new Capture();
|
||||
$captureInfo->setId($authId)
|
||||
->setAmount($amt);
|
||||
|
||||
$capture = $authorization->capture($captureInfo, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Retrieve Capture details
|
||||
// You can look up a capture by invoking the Capture::get method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$capture = Capture::get($capture->getId(), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$capture = Capture::get($request->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a capture</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Capture Id:
|
||||
<?php echo $capture->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $capture->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture);
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
// payments list.
|
||||
// API used: GET /v1/payments/payments
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Payment $createdPayment */
|
||||
$createdPayment = require 'CreatePayment.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
$paymentId = "PAY-2AH507590P6615624KRCTUSY";
|
||||
$paymentId = $createdPayment->getId();
|
||||
|
||||
// ### Retrieve payment
|
||||
// Retrieve the payment object by calling the
|
||||
@@ -20,20 +21,12 @@ $paymentId = "PAY-2AH507590P6615624KRCTUSY";
|
||||
// Payment ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// payments list.
|
||||
// API used: GET /v1/payments/payments
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
require 'CreatePayment.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
|
||||
@@ -21,20 +21,13 @@ use PayPal\Api\Payment;
|
||||
// Refer the method doc for valid values for keys
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payments = Payment::all(array('count' => 10, 'start_index' => 5), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
|
||||
$params = array('count' => 10, 'start_index' => 5);
|
||||
|
||||
$payments = Payment::all($params, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("List Payments", "Payment", null, $params, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup payment history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got <?php echo $payments->getCount(); ?> matching payments </div>
|
||||
<pre><?php echo $payments->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("List Payments", "Payment", null, $params, $payments);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// This sample code demonstrates how you can reauthorize a PayPal
|
||||
// account payment.
|
||||
// API used: v1/payments/authorization/{authorization_id}/reauthorize
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'AuthorizePayment.php';
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Amount;
|
||||
|
||||
@@ -18,34 +18,17 @@ use PayPal\Api\Amount;
|
||||
|
||||
try {
|
||||
|
||||
// ### Lookup authorization using the authorization id
|
||||
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
// ### Reauthorize with amount being reauthorized
|
||||
$authorization->setAmount($amount);
|
||||
|
||||
// ### Reauthorize with amount being reauthorized
|
||||
$authorization->setAmount($amount);
|
||||
$reauthorization = $authorization->reauthorize($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$reAuthorization = $authorization->reauthorize($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Reauthorize Payment", "Payment", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Reauthorize a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Reauthorization Id:
|
||||
<?php echo $reauthorization->getId();?>
|
||||
</div>
|
||||
<pre>
|
||||
<?php echo $reauthorization->toJSON(128);?>
|
||||
</pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization);
|
||||
|
||||
@@ -3,40 +3,13 @@
|
||||
// This sample code demonstrates how you can
|
||||
// process a refund on a Captured transaction.
|
||||
// API used: /v1/payments/capture/{<captureID>}/refund
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Capture $capture */
|
||||
$capture = require 'AuthorizationCapture.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
|
||||
try {
|
||||
// Create a mock authorization to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
|
||||
// ### Capture
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// Create a capture
|
||||
$captureInfo = new Capture();
|
||||
$captureInfo->setAmount($amt);
|
||||
|
||||
$capture = $authorization->capture($captureInfo, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Refund
|
||||
// Create a refund object indicating
|
||||
@@ -46,25 +19,14 @@ $refund = new Refund();
|
||||
$refund->setAmount($amt);
|
||||
|
||||
try {
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = getApiContext();
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = getApiContext($clientId, $clientSecret);
|
||||
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Refund Capture", "Capture", null, $refund, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a captured payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refund Capture:</div>
|
||||
<pre><?php echo $captureRefund->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refund, $captureRefund);
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
// void an authorized payment.
|
||||
// API used: /v1/payments/authorization/<{authorizationid}>/void"
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'AuthorizePayment.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
@@ -14,30 +15,17 @@ use PayPal\Api\Authorization;
|
||||
// by invoking the $authorization->void method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
// create an authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authorization->getId(), $apiContext);
|
||||
|
||||
// Void the authorization
|
||||
$voidedAuth = $authorization->void($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Void the authorization
|
||||
$voidedAuth = $authorization->void($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Void Authorization", "Authorization", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Void an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Voided authorization
|
||||
</div>
|
||||
<pre><?php echo $voidedAuth->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Void Authorization", "Authorization", $voidedAuth->getId(), null, $voidedAuth);
|
||||
|
||||
return $voidedAuth;
|
||||
|
||||
@@ -6,29 +6,28 @@
|
||||
// details of completed Sale Transaction.
|
||||
// API used: /v1/payments/sale/{sale-id}
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Payment $payment */
|
||||
$payment = require __DIR__ . '/../payments/CreatePayment.php';
|
||||
use PayPal\Api\Sale;
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
$saleId = '3RM92092UW5126232';
|
||||
// ### Get Sale From Created Payment
|
||||
// You can retrieve the sale Id from Related Resources for each transactions.
|
||||
$transactions = $payment->getTransactions();
|
||||
$relatedResources = $transactions[0]->getRelatedResources();
|
||||
$sale = $relatedResources[0]->getSale();
|
||||
$saleId = $sale->getId();
|
||||
|
||||
try {
|
||||
// ### Retrieve the sale object
|
||||
// Pass the ID of the sale
|
||||
// transaction from your payment resource.
|
||||
$sale = Sale::get($saleId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// ### Retrieve the sale object
|
||||
// Pass the ID of the sale
|
||||
// transaction from your payment resource.
|
||||
$sale = Sale::get($saleId, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Look Up A Sale", "Sale", $sale->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a sale</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving sale id: <?php echo $saleId;?></div>
|
||||
<pre><?php echo $sale->toJSON(128)?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Look Up A Sale", "Sale", $sale->getId(), null, $sale);
|
||||
|
||||
return $sale;
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
// using the Payments API.
|
||||
// API used: /v1/payments/sale/{sale-id}/refund
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Sale $sale */
|
||||
$sale = require 'GetSale.php';
|
||||
$saleId = $sale->getId();
|
||||
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Sale;
|
||||
@@ -17,14 +20,12 @@ use PayPal\Api\Sale;
|
||||
// field to mention fees refund details.
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency('USD')
|
||||
->setTotal('0.01');
|
||||
->setTotal('0.01');
|
||||
|
||||
// ### Refund object
|
||||
$refund = new Refund();
|
||||
$refund->setAmount($amt);
|
||||
|
||||
$saleId = '3RM92092UW5126232';
|
||||
|
||||
// ###Sale
|
||||
// A sale transaction.
|
||||
// Create a Sale object with the
|
||||
@@ -32,22 +33,18 @@ $saleId = '3RM92092UW5126232';
|
||||
$sale = new Sale();
|
||||
$sale->setId($saleId);
|
||||
try {
|
||||
// Refund the sale
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$sale->refund($refund, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = getApiContext($clientId, $clientSecret);
|
||||
|
||||
// Refund the sale
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$refundedSale = $sale->refund($refund, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a sale</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refunding sale id: <?php echo $saleId;?></div>
|
||||
<pre><?php echo $sale->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale);
|
||||
|
||||
return $refundedSale;
|
||||
|
||||
@@ -15,12 +15,15 @@ use PayPal\Api\CreditCard;
|
||||
// to be stored with PayPal.
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper");
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper");
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $card;
|
||||
|
||||
// ### Save card
|
||||
// Creates the credit card as a resource
|
||||
@@ -29,20 +32,12 @@ $card->setType("visa")
|
||||
// in future payments.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$card->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$card->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Save a credit card</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Saved a new credit card with id: <?php echo $card->getId();?></div>
|
||||
<pre><?php echo $card->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card);
|
||||
|
||||
return $card;
|
||||
|
||||
@@ -5,53 +5,20 @@
|
||||
// API used: /v1/vault/credit-card/{<creditCardId>}
|
||||
// NOTE: HTTP method used here is DELETE
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var CreditCard $card */
|
||||
$card = require 'CreateCreditCard.php';
|
||||
use PayPal\Api\CreditCard;
|
||||
|
||||
// Store a mock card that can be deleted later.
|
||||
// ### CreditCard
|
||||
// A resource representing a credit card that can be
|
||||
// used to fund a payment.
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper");
|
||||
|
||||
// ### 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 later.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$card = $card->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// ### Delete Card
|
||||
// Lookup and delete a saved credit card.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$creditCard = CreditCard::get($card->getId(), $apiContext);
|
||||
|
||||
$creditCard->delete($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
// ### Delete Card
|
||||
// Lookup and delete a saved credit card.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
|
||||
$creditCard = CreditCard::get($card->getId(), $apiContext);
|
||||
$creditCard->delete($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Delete a saved credit card</title>
|
||||
</head>
|
||||
<body>
|
||||
<p> Credit Card deleted Successfully</p>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, $creditCard);
|
||||
|
||||
@@ -6,30 +6,20 @@
|
||||
// API called: '/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;
|
||||
/** @var CreditCard $card */
|
||||
$card = require 'CreateCreditCard.php';
|
||||
|
||||
// The cardId can be obtained from a previous save credit
|
||||
// card operation. Use $card->getId()
|
||||
$cardId = "CARD-44D10970C24287906KRCTWNI";
|
||||
use PayPal\Api\CreditCard;
|
||||
|
||||
/// ### Retrieve card
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$card = CreditCard::get($cardId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$card = CreditCard::get($card->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Credit Card", "Credit Card", $card->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a saved credit card</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving saved credit card: <?php echo $cardId;?></div>
|
||||
<pre><?php echo $card->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Credit Card", "Credit Card", $card->getId(), null, $card);
|
||||
|
||||
return $card;
|
||||
|
||||
Reference in New Issue
Block a user