forked from LiveCarta/PayPal-PHP-SDK
Enabled Billing Plans and Agreements APIs
- Added API Classes, Samples, and Tests - Updated Functional Tests - Updated Documentation with new SDK Name - Updated Few Samples to use newer nicer result page
This commit is contained in:
@@ -3,12 +3,12 @@ Rest API Samples
|
||||
|
||||
This sample project is a simple web app that you can explore to understand what the payment APIs can do for you.
|
||||
|
||||
To try out the sample, run `composer update --no-dev` from the rest-api-sdk-php folder and you are all set.
|
||||
To try out the sample, run `composer update --no-dev` from the PayPal-PHP-SDK folder and you are all set.
|
||||
|
||||
The sample comes pre-configured with a test account but in case you need to try them against your account, you must
|
||||
|
||||
* Obtain your client id and client secret from the developer portal
|
||||
* Update the sdk_config.ini file with your new client id and secret.
|
||||
* Update the bootstrap.php file with your new client id and secret.
|
||||
|
||||
|
||||
If you are looking for a full fledged application that uses the new RESTful APIs, check out the Pizza store sample app at https://github.com/paypal/rest-api-sample-app-php
|
||||
|
||||
111
sample/billing/CreateBillingAgreementWithCreditCard.php
Normal file
111
sample/billing/CreateBillingAgreementWithCreditCard.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
// # Create Billing Agreement with Credit Card as Payment Source
|
||||
//
|
||||
// This sample code demonstrate how you can create a billing agreement, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement
|
||||
// API used: /v1/payments/billing-agreements
|
||||
|
||||
// Retrieving the Plan from the Create Update Sample. This would be used to
|
||||
// define Plan information to create an agreement. Make sure the plan you are using is in active state.
|
||||
/** @var Plan $createdPlan */
|
||||
$createdPlan = require 'UpdatePlan.php';
|
||||
|
||||
use PayPal\Api\Agreement;
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\ShippingAddress;
|
||||
use PayPal\Api\PayerInfo;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
|
||||
/* Create a new instance of Agreement object
|
||||
{
|
||||
"name": "DPRP",
|
||||
"description": "Payment with credit Card ",
|
||||
"start_date": "2015-06-17T9:45:04Z",
|
||||
"plan": {
|
||||
"id": "P-1WJ68935LL406420PUTENA2I"
|
||||
},
|
||||
"shipping_address": {
|
||||
"line1": "111 First Street",
|
||||
"city": "Saratoga",
|
||||
"state": "CA",
|
||||
"postal_code": "95070",
|
||||
"country_code": "US"
|
||||
},
|
||||
"payer": {
|
||||
"payment_method": "credit_card",
|
||||
"payer_info": {
|
||||
"email": "jaypatel512-facilitator@hotmail.com"
|
||||
},
|
||||
"funding_instruments": [
|
||||
{
|
||||
"credit_card": {
|
||||
"type": "visa",
|
||||
"number": "4417119669820331",
|
||||
"expire_month": "12",
|
||||
"expire_year": "2017",
|
||||
"cvv2": "128"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}*/
|
||||
$agreement = new Agreement();
|
||||
|
||||
$agreement->setName('DPRP')
|
||||
->setDescription('Payment with credit Card')
|
||||
->setStartDate('2015-06-17T9:45:04Z');
|
||||
|
||||
// Add Plan ID
|
||||
// Please note that the plan Id should be only set in this case.
|
||||
$plan = new Plan();
|
||||
$plan->setId($createdPlan->getId());
|
||||
$agreement->setPlan($plan);
|
||||
|
||||
// Add Payer
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod('credit_card')
|
||||
->setPayerInfo(new PayerInfo(['email' => 'jaypatel512-facilitator@hotmail.com']));
|
||||
|
||||
// Add Credit Card to Funding Instruments
|
||||
$creditCard = new CreditCard();
|
||||
$creditCard->setType('visa')
|
||||
->setNumber('4417119669820331')
|
||||
->setExpireMonth('12')
|
||||
->setExpireYear('2017')
|
||||
->setCvv2('128');
|
||||
|
||||
$fundingInstrument = new FundingInstrument();
|
||||
$fundingInstrument->setCreditCard($creditCard);
|
||||
$payer->setFundingInstruments(array($fundingInstrument));
|
||||
//Add Payer to Agreement
|
||||
$agreement->setPayer($payer);
|
||||
|
||||
// Add Shipping Address
|
||||
$shippingAddress = new ShippingAddress();
|
||||
$shippingAddress->setLine1('111 First Street')
|
||||
->setCity('Saratoga')
|
||||
->setState('CA')
|
||||
->setPostalCode('95070')
|
||||
->setCountryCode('US');
|
||||
$agreement->setShippingAddress($shippingAddress);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $agreement;
|
||||
|
||||
// ### Create Agreement
|
||||
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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $agreement);
|
||||
|
||||
return $agreement;
|
||||
91
sample/billing/CreateBillingAgreementWithPayPal.php
Normal file
91
sample/billing/CreateBillingAgreementWithPayPal.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
// # Create Billing Agreement with PayPal as Payment Source
|
||||
//
|
||||
// This sample code demonstrate how you can create a billing agreement, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement
|
||||
// API used: /v1/payments/billing-agreements
|
||||
|
||||
// Retrieving the Plan from the Create Update Sample. This would be used to
|
||||
// define Plan information to create an agreement. Make sure the plan you are using is in active state.
|
||||
/** @var Plan $createdPlan */
|
||||
$createdPlan = require 'UpdatePlan.php';
|
||||
|
||||
use PayPal\Api\Agreement;
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\ShippingAddress;
|
||||
|
||||
/* Create a new instance of Agreement object
|
||||
{
|
||||
"name": "Base Agreement",
|
||||
"description": "Basic agreement",
|
||||
"start_date": "2015-06-17T9:45:04Z",
|
||||
"plan": {
|
||||
"id": "P-1WJ68935LL406420PUTENA2I"
|
||||
},
|
||||
"payer": {
|
||||
"payment_method": "paypal"
|
||||
},
|
||||
"shipping_address": {
|
||||
"line1": "111 First Street",
|
||||
"city": "Saratoga",
|
||||
"state": "CA",
|
||||
"postal_code": "95070",
|
||||
"country_code": "US"
|
||||
}
|
||||
}*/
|
||||
$agreement = new Agreement();
|
||||
|
||||
$agreement->setName('Base Agreement')
|
||||
->setDescription('Basic Agreement')
|
||||
->setStartDate('2015-06-17T9:45:04Z');
|
||||
|
||||
// Add Plan ID
|
||||
// Please note that the plan Id should be only set in this case.
|
||||
$plan = new Plan();
|
||||
$plan->setId($createdPlan->getId());
|
||||
$agreement->setPlan($plan);
|
||||
|
||||
// Add Payer
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod('paypal');
|
||||
$agreement->setPayer($payer);
|
||||
|
||||
// Add Shipping Address
|
||||
$shippingAddress = new ShippingAddress();
|
||||
$shippingAddress->setLine1('111 First Street')
|
||||
->setCity('Saratoga')
|
||||
->setState('CA')
|
||||
->setPostalCode('95070')
|
||||
->setCountryCode('US');
|
||||
$agreement->setShippingAddress($shippingAddress);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $agreement;
|
||||
|
||||
// ### Create Agreement
|
||||
try {
|
||||
// Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
|
||||
$agreement = $agreement->create($apiContext);
|
||||
|
||||
// ### Get redirect url
|
||||
// The API response provides the url that you must redirect
|
||||
// the buyer to. Retrieve the url from the $agreement->getLinks()
|
||||
// method
|
||||
foreach ($agreement->getLinks() as $link) {
|
||||
if ($link->getRel() == 'approval_url') {
|
||||
$approvalUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Created Billing Agreement. Please visit the URL to Approve.", "Agreement", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $agreement);
|
||||
|
||||
return $agreement;
|
||||
72
sample/billing/CreatePlan.php
Normal file
72
sample/billing/CreatePlan.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
// # Create Plan Sample
|
||||
//
|
||||
// This sample code demonstrate how you can create a billing plan, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#create-a-plan
|
||||
// API used: /v1/payments/billing-plans
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Api\PaymentDefinition;
|
||||
use PayPal\Api\MerchantPreferences;
|
||||
use PayPal\Api\Currency;
|
||||
use PayPal\Api\ChargeModel;
|
||||
|
||||
// Create a new instance of Plan object
|
||||
$plan = new Plan();
|
||||
|
||||
// # Basic Information
|
||||
// Fill up the basic information that is required for the plan
|
||||
$plan->setName('T-Shirt of the Month Club Plan')
|
||||
->setDescription('Template creation.')
|
||||
->setType('fixed');
|
||||
|
||||
// # Payment definitions for this billing plan.
|
||||
$paymentDefinition = new PaymentDefinition();
|
||||
|
||||
// The possible values for such setters are mentioned in the setter method documentation.
|
||||
// Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
|
||||
// You should be able to see the acceptable values in the comments.
|
||||
$paymentDefinition->setName('Regular Payments')
|
||||
->setType('REGULAR')
|
||||
->setFrequency('Month')
|
||||
->setFrequencyInterval("2")
|
||||
->setCycles("12")
|
||||
->setAmount(new Currency(['value' => '100', 'currency' => 'USD']));
|
||||
|
||||
// Charge Models
|
||||
$chargeModel = new ChargeModel();
|
||||
$chargeModel->setType('SHIPPING')
|
||||
->setAmount(new Currency(['value' => '10', 'currency' => 'USD']));
|
||||
|
||||
$paymentDefinition->setChargeModels(array($chargeModel));
|
||||
|
||||
$merchantPreferences = new MerchantPreferences();
|
||||
$baseUrl = getBaseUrl();
|
||||
$merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true")
|
||||
->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false")
|
||||
->setAutoBillAmount("YES")
|
||||
->setInitialFailAmountAction("CONTINUE")
|
||||
->setMaxFailAttempts("0")
|
||||
->setSetupFee(new Currency(['value' => '1', 'currency' => 'USD']));
|
||||
|
||||
|
||||
$plan->setPaymentDefinitions(array($paymentDefinition));
|
||||
$plan->setMerchantPreferences($merchantPreferences);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Created Plan", "Plan", $output->getId(), $request, $output);
|
||||
|
||||
return $output;
|
||||
22
sample/billing/ExecuteAgreement.php
Normal file
22
sample/billing/ExecuteAgreement.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
session_start();
|
||||
if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
$token = $_GET['token'];
|
||||
|
||||
$agreement = new \PayPal\Api\Agreement();
|
||||
|
||||
try {
|
||||
$agreement->execute($token, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);
|
||||
|
||||
} else {
|
||||
ResultPrinter::printResult("User Cancelled the Approval", null);
|
||||
}
|
||||
25
sample/billing/GetBillingAgreement.php
Normal file
25
sample/billing/GetBillingAgreement.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// # Get Billing Agreement Sample
|
||||
//
|
||||
// This sample code demonstrate how you can get a billing agreement, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement
|
||||
// API used: /v1/payments/billing-agreements/<Agreement-Id>
|
||||
|
||||
// Retrieving the Agreement object from Create Agreement From Credit Card Sample
|
||||
/** @var Agreement $createdAgreement */
|
||||
$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php';
|
||||
|
||||
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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $agreement);
|
||||
|
||||
return $agreement;
|
||||
25
sample/billing/GetPlan.php
Normal file
25
sample/billing/GetPlan.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// # Get Plan Sample
|
||||
//
|
||||
// This sample code demonstrate how you can get a billing plan, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan
|
||||
// API used: /v1/payments/billing-plans
|
||||
|
||||
// Retrieving the Plan object from Create Plan Sample
|
||||
/** @var Plan $createdPlan */
|
||||
$createdPlan = require 'CreatePlan.php';
|
||||
|
||||
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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Retrieved a Plan", "Plan", $plan->getId(), null, $plan);
|
||||
|
||||
return $plan;
|
||||
30
sample/billing/ListPlans.php
Normal file
30
sample/billing/ListPlans.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// # Get List of Plan Sample
|
||||
//
|
||||
// This sample code demonstrate how you can get a list of billing plan, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#list-plans
|
||||
// API used: /v1/payments/billing-plans
|
||||
|
||||
// Retrieving the Plan object from Create Plan Sample to demonstrate the List
|
||||
/** @var Plan $createdPlan */
|
||||
$createdPlan = require 'CreatePlan.php';
|
||||
|
||||
use PayPal\Api\Plan;
|
||||
|
||||
try {
|
||||
// Get the list of all plans
|
||||
// You can modify different params to change the return list.
|
||||
// The explanation about each pagination information could be found here
|
||||
// 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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("List of Plans", "Plan", null, $params, $planList);
|
||||
|
||||
return $planList;
|
||||
35
sample/billing/ReactivateBillingAgreement.php
Normal file
35
sample/billing/ReactivateBillingAgreement.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// # Reactivate an agreement
|
||||
//
|
||||
// This sample code demonstrate how you can reactivate a billing agreement, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement
|
||||
// API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend
|
||||
|
||||
// Retrieving the Agreement object from Suspend Agreement Sample to demonstrate the List
|
||||
/** @var Agreement $suspendedAgreement */
|
||||
$suspendedAgreement = require 'SuspendBillingAgreement.php';
|
||||
|
||||
use PayPal\Api\Agreement;
|
||||
use PayPal\Api\AgreementStateDescriptor;
|
||||
|
||||
//Create an Agreement State Descriptor, explaining the reason to suspend.
|
||||
$agreementStateDescriptor = new AgreementStateDescriptor();
|
||||
$agreementStateDescriptor->setNote("Reactivating the agreement");
|
||||
|
||||
try {
|
||||
|
||||
$suspendedAgreement->reActivate($agreementStateDescriptor, $apiContext);
|
||||
|
||||
// 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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $agreement);
|
||||
|
||||
return $agreement;
|
||||
35
sample/billing/SuspendBillingAgreement.php
Normal file
35
sample/billing/SuspendBillingAgreement.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// # Suspend an agreement
|
||||
//
|
||||
// This sample code demonstrate how you can suspend a billing agreement, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement
|
||||
// API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend
|
||||
|
||||
// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
|
||||
/** @var Agreement $createdAgreement */
|
||||
$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php';
|
||||
|
||||
use PayPal\Api\Agreement;
|
||||
use PayPal\Api\AgreementStateDescriptor;
|
||||
|
||||
//Create an Agreement State Descriptor, explaining the reason to suspend.
|
||||
$agreementStateDescriptor = new AgreementStateDescriptor();
|
||||
$agreementStateDescriptor->setNote("Suspending the agreement");
|
||||
|
||||
try {
|
||||
|
||||
$createdAgreement->suspend($agreementStateDescriptor, $apiContext);
|
||||
|
||||
// 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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Suspended the Agreement", "Agreement", $agreement->getId(), $agreementStateDescriptor, $agreement);
|
||||
|
||||
return $agreement;
|
||||
47
sample/billing/UpdateBillingAgreement.php
Normal file
47
sample/billing/UpdateBillingAgreement.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
// # Update an agreement
|
||||
//
|
||||
// This sample code demonstrate how you can update a billing agreement, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement
|
||||
// API used: /v1/payments/billing-agreements/<Agreement-Id>
|
||||
|
||||
// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
|
||||
/** @var Agreement $createdAgreement */
|
||||
$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php';
|
||||
|
||||
use PayPal\Api\Agreement;
|
||||
use PayPal\Api\PatchRequest;
|
||||
use PayPal\Api\Patch;
|
||||
|
||||
$patch = new Patch();
|
||||
|
||||
$patch->setOp('replace')
|
||||
->setPath('/')
|
||||
->setValue(json_decode('{
|
||||
"description": "New Description",
|
||||
"shipping_address": {
|
||||
"line1": "2065 Hamilton Ave",
|
||||
"city": "San Jose",
|
||||
"state": "CA",
|
||||
"postal_code": "95125",
|
||||
"country_code": "US"
|
||||
}
|
||||
}'));
|
||||
$patchRequest = new PatchRequest();
|
||||
$patchRequest->addPatch($patch);
|
||||
try {
|
||||
$createdAgreement->update($patchRequest, $apiContext);
|
||||
|
||||
// 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());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", $agreement->getId(), $patchRequest, $agreement);
|
||||
|
||||
return $agreement;
|
||||
45
sample/billing/UpdatePlan.php
Normal file
45
sample/billing/UpdatePlan.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
// # Update a plan
|
||||
//
|
||||
// This sample code demonstrate how you can update a billing plan, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan
|
||||
// API used: /v1/payments/billing-plans/<Plan-Id>
|
||||
|
||||
// ### Making Plan Active
|
||||
// This example demonstrate how you could activate the Plan.
|
||||
|
||||
// Retrieving the Plan object from Create Plan Sample to demonstrate the List
|
||||
/** @var Plan $createdPlan */
|
||||
$createdPlan = require 'CreatePlan.php';
|
||||
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Api\PatchRequest;
|
||||
use PayPal\Api\Patch;
|
||||
use PayPal\Common\PPModel;
|
||||
try {
|
||||
$patch = new Patch();
|
||||
|
||||
$value = new PPModel('{
|
||||
"state":"ACTIVE"
|
||||
}');
|
||||
|
||||
$patch->setOp('replace')
|
||||
->setPath('/')
|
||||
->setValue($value);
|
||||
$patchRequest = new PatchRequest();
|
||||
$patchRequest->addPatch($patch);
|
||||
|
||||
$createdPlan->update($patchRequest, $apiContext);
|
||||
|
||||
$plan = Plan::get($createdPlan->getId(), $apiContext);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Updated the Plan to Active State", "Plan", $plan->getId(), $patchRequest, $plan);
|
||||
|
||||
return $plan;
|
||||
@@ -12,25 +12,80 @@ use PayPal\Api\Payment;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
|
||||
/**
|
||||
* Helper Class for Printing Results
|
||||
*
|
||||
* Class ResultPrinter
|
||||
*/
|
||||
class ResultPrinter {
|
||||
|
||||
function print_result($title, $objectName, $objectId = null, $output = null)
|
||||
{
|
||||
echo "<h3>$title</h3>";
|
||||
private static $printResultCounter = 0;
|
||||
|
||||
if ($objectId) {
|
||||
echo "<div> Created " . ($objectName ? $objectName : "Object") . " with ID: $objectId</div>";
|
||||
public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null)
|
||||
{
|
||||
if (self::$printResultCounter == 0) {
|
||||
include "header.html";
|
||||
echo '<br />
|
||||
<div class="row"><div class="col-md-2 pull-left"><a href="../index.html"><h4>❮❮ Back to Samples</h4></a><br /><br /></div>
|
||||
<div class="col-md-1 pull-right"><img src="../images/pp_v_rgb.png" height="70" /></div> </div><div class="clearfix visible-xs-block"></div>';
|
||||
echo '<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">';
|
||||
}
|
||||
self::$printResultCounter++;
|
||||
echo '
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading" 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>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="step-'.self::$printResultCounter.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-'. self::$printResultCounter . '">
|
||||
<div class="panel-body">
|
||||
';
|
||||
|
||||
if ($objectId) {
|
||||
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>';
|
||||
|
||||
echo '<div class="hidden-lg"><ul class="nav nav-tabs" role="tablist">
|
||||
<li role="presentation" ><a href="#step-'.self::$printResultCounter .'-request" role="tab" data-toggle="tab">Request</a></li>
|
||||
<li role="presentation" class="active"><a href="#step-'.self::$printResultCounter .'-response" role="tab" data-toggle="tab">Response</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<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);
|
||||
echo '</div></div></div></div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
if ($output) {
|
||||
if (is_a($output, 'PayPal\Common\PPModel')) {
|
||||
/** @var $output \PayPal\Common\PPModel */
|
||||
echo "<pre>" . $output->toJSON(128) . "</pre>";
|
||||
} elseif (is_string($output)) {
|
||||
echo "<pre>$output</pre>";
|
||||
protected static function printObject($object)
|
||||
{
|
||||
if ($object) {
|
||||
if (is_a($object, 'PayPal\Common\PPModel')) {
|
||||
/** @var $object \PayPal\Common\PPModel */
|
||||
echo '<pre class="prettyprint">' . $object->toJSON(128) . "</pre>";
|
||||
} elseif (is_string($object)) {
|
||||
echo "<pre>$object</pre>";
|
||||
} else {
|
||||
echo "<pre>";
|
||||
print_r($object);
|
||||
echo "</pre>";
|
||||
}
|
||||
} else {
|
||||
echo "<span>No Data</span>";
|
||||
}
|
||||
}
|
||||
echo "<hr />";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,393 @@ 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
|
||||
|
||||
tableOfContents = [
|
||||
{
|
||||
"type": "folder",
|
||||
"data": {
|
||||
"path": "billing",
|
||||
"title": "billing"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"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/billing/CreateBillingAgreementWithCreditCard.php",
|
||||
"projectPath": "billing/CreateBillingAgreementWithCreditCard.php",
|
||||
"targetPath": "billing/CreateBillingAgreementWithCreditCard",
|
||||
"pageTitle": "billing/CreateBillingAgreementWithCreditCard",
|
||||
"title": "CreateBillingAgreementWithCreditCard"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Create Billing Agreement with Credit Card as Payment Source",
|
||||
"slug": "create-billing-agreement-with-credit-card-as-payment-source"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Create Agreement",
|
||||
"slug": "create-agreement"
|
||||
},
|
||||
"depth": 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/billing/CreateBillingAgreementWithPayPal.php",
|
||||
"projectPath": "billing/CreateBillingAgreementWithPayPal.php",
|
||||
"targetPath": "billing/CreateBillingAgreementWithPayPal",
|
||||
"pageTitle": "billing/CreateBillingAgreementWithPayPal",
|
||||
"title": "CreateBillingAgreementWithPayPal"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Create Billing Agreement with PayPal as Payment Source",
|
||||
"slug": "create-billing-agreement-with-paypal-as-payment-source"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Create Agreement",
|
||||
"slug": "create-agreement"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Get redirect url",
|
||||
"slug": "get-redirect-url"
|
||||
},
|
||||
"depth": 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/billing/CreatePlan.php",
|
||||
"projectPath": "billing/CreatePlan.php",
|
||||
"targetPath": "billing/CreatePlan",
|
||||
"pageTitle": "billing/CreatePlan",
|
||||
"title": "CreatePlan"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Create Plan Sample",
|
||||
"slug": "create-plan-sample"
|
||||
},
|
||||
"depth": 1
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Basic Information",
|
||||
"slug": "basic-information"
|
||||
},
|
||||
"depth": 1
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Payment definitions for this billing plan.",
|
||||
"slug": "payment-definitions-for-this-billing-plan"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Create Plan",
|
||||
"slug": "create-plan"
|
||||
},
|
||||
"depth": 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/billing/ExecuteAgreement.php",
|
||||
"projectPath": "billing/ExecuteAgreement.php",
|
||||
"targetPath": "billing/ExecuteAgreement",
|
||||
"pageTitle": "billing/ExecuteAgreement",
|
||||
"title": "ExecuteAgreement"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": []
|
||||
}, {
|
||||
"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/billing/GetBillingAgreement.php",
|
||||
"projectPath": "billing/GetBillingAgreement.php",
|
||||
"targetPath": "billing/GetBillingAgreement",
|
||||
"pageTitle": "billing/GetBillingAgreement",
|
||||
"title": "GetBillingAgreement"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Get Billing Agreement Sample",
|
||||
"slug": "get-billing-agreement-sample"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"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/billing/GetPlan.php",
|
||||
"projectPath": "billing/GetPlan.php",
|
||||
"targetPath": "billing/GetPlan",
|
||||
"pageTitle": "billing/GetPlan",
|
||||
"title": "GetPlan"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Get Plan Sample",
|
||||
"slug": "get-plan-sample"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"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/billing/ListPlans.php",
|
||||
"projectPath": "billing/ListPlans.php",
|
||||
"targetPath": "billing/ListPlans",
|
||||
"pageTitle": "billing/ListPlans",
|
||||
"title": "ListPlans"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Get List of Plan Sample",
|
||||
"slug": "get-list-of-plan-sample"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"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/billing/ReactivateBillingAgreement.php",
|
||||
"projectPath": "billing/ReactivateBillingAgreement.php",
|
||||
"targetPath": "billing/ReactivateBillingAgreement",
|
||||
"pageTitle": "billing/ReactivateBillingAgreement",
|
||||
"title": "ReactivateBillingAgreement"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Reactivate an agreement",
|
||||
"slug": "reactivate-an-agreement"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"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/billing/SuspendBillingAgreement.php",
|
||||
"projectPath": "billing/SuspendBillingAgreement.php",
|
||||
"targetPath": "billing/SuspendBillingAgreement",
|
||||
"pageTitle": "billing/SuspendBillingAgreement",
|
||||
"title": "SuspendBillingAgreement"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Suspend an agreement",
|
||||
"slug": "suspend-an-agreement"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"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/billing/UpdateBillingAgreement.php",
|
||||
"projectPath": "billing/UpdateBillingAgreement.php",
|
||||
"targetPath": "billing/UpdateBillingAgreement",
|
||||
"pageTitle": "billing/UpdateBillingAgreement",
|
||||
"title": "UpdateBillingAgreement"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Update an agreement",
|
||||
"slug": "update-an-agreement"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"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/billing/UpdatePlan.php",
|
||||
"projectPath": "billing/UpdatePlan.php",
|
||||
"targetPath": "billing/UpdatePlan",
|
||||
"pageTitle": "billing/UpdatePlan",
|
||||
"title": "UpdatePlan"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Update a plan",
|
||||
"slug": "update-a-plan"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Making Plan Active",
|
||||
"slug": "making-plan-active"
|
||||
},
|
||||
"depth": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "folder",
|
||||
"data": {
|
||||
"path": "invoice",
|
||||
|
||||
85
sample/doc/billing/CreateBillingAgreementWithCreditCard.html
Normal file
85
sample/doc/billing/CreateBillingAgreementWithCreditCard.html
Normal file
@@ -0,0 +1,85 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/CreateBillingAgreementWithCreditCard</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="billing/CreateBillingAgreementWithCreditCard"><meta name="groc-project-path" content="billing/CreateBillingAgreementWithCreditCard.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">billing/CreateBillingAgreementWithCreditCard.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-billing-agreement-with-credit-card-as-payment-source">Create Billing Agreement with Credit Card as Payment Source</h1>
|
||||
<p>This sample code demonstrate how you can create a billing agreement, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement</a>
|
||||
API used: /v1/payments/billing-agreements</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan from the Create Update Sample. This would be used to
|
||||
define Plan information to create an agreement. Make sure the plan you are using is in active state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Plan $createdPlan */</span>
|
||||
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'UpdatePlan.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Plan</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">ShippingAddress</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PayerInfo</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-comment">/* Create a new instance of Agreement object
|
||||
{
|
||||
"name": "DPRP",
|
||||
"description": "Payment with credit Card ",
|
||||
"start_date": "2015-06-17T9:45:04Z",
|
||||
"plan": {
|
||||
"id": "P-1WJ68935LL406420PUTENA2I"
|
||||
},
|
||||
"shipping_address": {
|
||||
"line1": "111 First Street",
|
||||
"city": "Saratoga",
|
||||
"state": "CA",
|
||||
"postal_code": "95070",
|
||||
"country_code": "US"
|
||||
},
|
||||
"payer": {
|
||||
"payment_method": "credit_card",
|
||||
"payer_info": {
|
||||
"email": "jaypatel512-facilitator@hotmail.com"
|
||||
},
|
||||
"funding_instruments": [
|
||||
{
|
||||
"credit_card": {
|
||||
"type": "visa",
|
||||
"number": "4417119669820331",
|
||||
"expire_month": "12",
|
||||
"expire_year": "2017",
|
||||
"cvv2": "128"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}*/</span>
|
||||
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">new</span> Agreement();
|
||||
|
||||
<span class="hljs-variable">$agreement</span>->setName(<span class="hljs-string">'DPRP'</span>)
|
||||
->setDescription(<span class="hljs-string">'Payment with credit Card'</span>)
|
||||
->setStartDate(<span class="hljs-string">'2015-06-17T9:45:04Z'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Plan ID
|
||||
Please note that the plan Id should be only set in this case.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$plan</span> = <span class="hljs-keyword">new</span> Plan();
|
||||
<span class="hljs-variable">$plan</span>->setId(<span class="hljs-variable">$createdPlan</span>->getId());
|
||||
<span class="hljs-variable">$agreement</span>->setPlan(<span class="hljs-variable">$plan</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Payer</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>)
|
||||
->setPayerInfo(<span class="hljs-keyword">new</span> PayerInfo([<span class="hljs-string">'email'</span> => <span class="hljs-string">'jaypatel512-facilitator@hotmail.com'</span>]));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Credit Card to Funding Instruments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$creditCard</span> = <span class="hljs-keyword">new</span> CreditCard();
|
||||
<span class="hljs-variable">$creditCard</span>->setType(<span class="hljs-string">'visa'</span>)
|
||||
->setNumber(<span class="hljs-string">'4417119669820331'</span>)
|
||||
->setExpireMonth(<span class="hljs-string">'12'</span>)
|
||||
->setExpireYear(<span class="hljs-string">'2017'</span>)
|
||||
->setCvv2(<span class="hljs-string">'128'</span>);
|
||||
|
||||
<span class="hljs-variable">$fundingInstrument</span> = <span class="hljs-keyword">new</span> FundingInstrument();
|
||||
<span class="hljs-variable">$fundingInstrument</span>->setCreditCard(<span class="hljs-variable">$creditCard</span>);
|
||||
<span class="hljs-variable">$payer</span>->setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fundingInstrument</span>));
|
||||
<span class="hljs-comment">//Add Payer to Agreement</span>
|
||||
<span class="hljs-variable">$agreement</span>->setPayer(<span class="hljs-variable">$payer</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Shipping Address</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$shippingAddress</span> = <span class="hljs-keyword">new</span> ShippingAddress();
|
||||
<span class="hljs-variable">$shippingAddress</span>->setLine1(<span class="hljs-string">'111 First Street'</span>)
|
||||
->setCity(<span class="hljs-string">'Saratoga'</span>)
|
||||
->setState(<span class="hljs-string">'CA'</span>)
|
||||
->setPostalCode(<span class="hljs-string">'95070'</span>)
|
||||
->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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<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">$agreement</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|
||||
65
sample/doc/billing/CreateBillingAgreementWithPayPal.html
Normal file
65
sample/doc/billing/CreateBillingAgreementWithPayPal.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/CreateBillingAgreementWithPayPal</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="billing/CreateBillingAgreementWithPayPal"><meta name="groc-project-path" content="billing/CreateBillingAgreementWithPayPal.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">billing/CreateBillingAgreementWithPayPal.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-billing-agreement-with-paypal-as-payment-source">Create Billing Agreement with PayPal as Payment Source</h1>
|
||||
<p>This sample code demonstrate how you can create a billing agreement, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement</a>
|
||||
API used: /v1/payments/billing-agreements</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan from the Create Update Sample. This would be used to
|
||||
define Plan information to create an agreement. Make sure the plan you are using is in active state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Plan $createdPlan */</span>
|
||||
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'UpdatePlan.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Plan</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">ShippingAddress</span>;
|
||||
|
||||
<span class="hljs-comment">/* Create a new instance of Agreement object
|
||||
{
|
||||
"name": "Base Agreement",
|
||||
"description": "Basic agreement",
|
||||
"start_date": "2015-06-17T9:45:04Z",
|
||||
"plan": {
|
||||
"id": "P-1WJ68935LL406420PUTENA2I"
|
||||
},
|
||||
"payer": {
|
||||
"payment_method": "paypal"
|
||||
},
|
||||
"shipping_address": {
|
||||
"line1": "111 First Street",
|
||||
"city": "Saratoga",
|
||||
"state": "CA",
|
||||
"postal_code": "95070",
|
||||
"country_code": "US"
|
||||
}
|
||||
}*/</span>
|
||||
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">new</span> Agreement();
|
||||
|
||||
<span class="hljs-variable">$agreement</span>->setName(<span class="hljs-string">'Base Agreement'</span>)
|
||||
->setDescription(<span class="hljs-string">'Basic Agreement'</span>)
|
||||
->setStartDate(<span class="hljs-string">'2015-06-17T9:45:04Z'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Plan ID
|
||||
Please note that the plan Id should be only set in this case.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$plan</span> = <span class="hljs-keyword">new</span> Plan();
|
||||
<span class="hljs-variable">$plan</span>->setId(<span class="hljs-variable">$createdPlan</span>->getId());
|
||||
<span class="hljs-variable">$agreement</span>->setPlan(<span class="hljs-variable">$plan</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Payer</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">'paypal'</span>);
|
||||
<span class="hljs-variable">$agreement</span>->setPayer(<span class="hljs-variable">$payer</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Shipping Address</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$shippingAddress</span> = <span class="hljs-keyword">new</span> ShippingAddress();
|
||||
<span class="hljs-variable">$shippingAddress</span>->setLine1(<span class="hljs-string">'111 First Street'</span>)
|
||||
->setCity(<span class="hljs-string">'Saratoga'</span>)
|
||||
->setState(<span class="hljs-string">'CA'</span>)
|
||||
->setPostalCode(<span class="hljs-string">'95070'</span>)
|
||||
->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>);</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 $agreement->getLinks()
|
||||
method</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$agreement</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>;
|
||||
}
|
||||
}
|
||||
|
||||
} <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>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Created Billing Agreement. Please visit the URL to Approve."</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-string">"<a href='$approvalUrl' >$approvalUrl</a>"</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$agreement</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|
||||
46
sample/doc/billing/CreatePlan.html
Normal file
46
sample/doc/billing/CreatePlan.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/CreatePlan</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="billing/CreatePlan"><meta name="groc-project-path" content="billing/CreatePlan.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">billing/CreatePlan.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-plan-sample">Create Plan Sample</h1>
|
||||
<p>This sample code demonstrate how you can create a billing plan, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#create-a-plan">https://developer.paypal.com/webapps/developer/docs/api/#create-a-plan</a>
|
||||
API used: /v1/payments/billing-plans</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">Plan</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentDefinition</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">MerchantPreferences</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Currency</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ChargeModel</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new instance of Plan object</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$plan</span> = <span class="hljs-keyword">new</span> Plan();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="basic-information">Basic Information</h1>
|
||||
<p>Fill up the basic information that is required for the plan</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$plan</span>->setName(<span class="hljs-string">'T-Shirt of the Month Club Plan'</span>)
|
||||
->setDescription(<span class="hljs-string">'Template creation.'</span>)
|
||||
->setType(<span class="hljs-string">'fixed'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="payment-definitions-for-this-billing-plan">Payment definitions for this billing plan.</h1></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$paymentDefinition</span> = <span class="hljs-keyword">new</span> PaymentDefinition();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>The possible values for such setters are mentioned in the setter method documentation.
|
||||
Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
|
||||
You should be able to see the acceptable values in the comments.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$paymentDefinition</span>->setName(<span class="hljs-string">'Regular Payments'</span>)
|
||||
->setType(<span class="hljs-string">'REGULAR'</span>)
|
||||
->setFrequency(<span class="hljs-string">'Month'</span>)
|
||||
->setFrequencyInterval(<span class="hljs-string">"2"</span>)
|
||||
->setCycles(<span class="hljs-string">"12"</span>)
|
||||
->setAmount(<span class="hljs-keyword">new</span> Currency([<span class="hljs-string">'value'</span> => <span class="hljs-string">'100'</span>, <span class="hljs-string">'currency'</span> => <span class="hljs-string">'USD'</span>]));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Charge Models</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$chargeModel</span> = <span class="hljs-keyword">new</span> ChargeModel();
|
||||
<span class="hljs-variable">$chargeModel</span>->setType(<span class="hljs-string">'SHIPPING'</span>)
|
||||
->setAmount(<span class="hljs-keyword">new</span> Currency([<span class="hljs-string">'value'</span> => <span class="hljs-string">'10'</span>, <span class="hljs-string">'currency'</span> => <span class="hljs-string">'USD'</span>]));
|
||||
|
||||
<span class="hljs-variable">$paymentDefinition</span>->setChargeModels(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$chargeModel</span>));
|
||||
|
||||
<span class="hljs-variable">$merchantPreferences</span> = <span class="hljs-keyword">new</span> MerchantPreferences();
|
||||
<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>)
|
||||
->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>]));
|
||||
|
||||
|
||||
<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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Created Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$output</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$output</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$output</span>;</div></div></div></div></body></html>
|
||||
22
sample/doc/billing/ExecuteAgreement.html
Normal file
22
sample/doc/billing/ExecuteAgreement.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/ExecuteAgreement</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="billing/ExecuteAgreement"><meta name="groc-project-path" content="billing/ExecuteAgreement.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">billing/ExecuteAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span>
|
||||
|
||||
<span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
session_start();
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
|
||||
|
||||
<span class="hljs-variable">$token</span> = <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>];
|
||||
|
||||
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Agreement();
|
||||
|
||||
<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">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>);
|
||||
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
ResultPrinter::printResult(<span class="hljs-string">"User Cancelled the Approval"</span>, <span class="hljs-keyword">null</span>);
|
||||
}</div></div></div></div></body></html>
|
||||
19
sample/doc/billing/GetBillingAgreement.html
Normal file
19
sample/doc/billing/GetBillingAgreement.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/GetBillingAgreement</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="billing/GetBillingAgreement"><meta name="groc-project-path" content="billing/GetBillingAgreement.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">billing/GetBillingAgreement.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="get-billing-agreement-sample">Get Billing Agreement Sample</h1>
|
||||
<p>This sample code demonstrate how you can get a billing agreement, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement</a>
|
||||
API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement From Credit Card Sample</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Agreement $createdAgreement */</span>
|
||||
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBillingAgreementWithCreditCard.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
|
||||
<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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<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">$agreement</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|
||||
19
sample/doc/billing/GetPlan.html
Normal file
19
sample/doc/billing/GetPlan.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/GetPlan</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="billing/GetPlan"><meta name="groc-project-path" content="billing/GetPlan.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">billing/GetPlan.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="get-plan-sample">Get Plan Sample</h1>
|
||||
<p>This sample code demonstrate how you can get a billing plan, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan">https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan</a>
|
||||
API used: /v1/payments/billing-plans</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan object from Create Plan Sample</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Plan $createdPlan */</span>
|
||||
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePlan.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Plan</span>;
|
||||
|
||||
<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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<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">$plan</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$plan</span>;</div></div></div></div></body></html>
|
||||
22
sample/doc/billing/ListPlans.html
Normal file
22
sample/doc/billing/ListPlans.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/ListPlans</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="billing/ListPlans"><meta name="groc-project-path" content="billing/ListPlans.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">billing/ListPlans.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="get-list-of-plan-sample">Get List of Plan Sample</h1>
|
||||
<p>This sample code demonstrate how you can get a list of billing plan, as documented 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>
|
||||
API used: /v1/payments/billing-plans</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan object from Create Plan Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Plan $createdPlan */</span>
|
||||
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePlan.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Plan</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the list of all plans
|
||||
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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<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">$planList</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$planList</span>;</div></div></div></div></body></html>
|
||||
26
sample/doc/billing/ReactivateBillingAgreement.html
Normal file
26
sample/doc/billing/ReactivateBillingAgreement.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/ReactivateBillingAgreement</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="billing/ReactivateBillingAgreement"><meta name="groc-project-path" content="billing/ReactivateBillingAgreement.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">billing/ReactivateBillingAgreement.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="reactivate-an-agreement">Reactivate an agreement</h1>
|
||||
<p>This sample code demonstrate how you can reactivate a billing agreement, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement</a>
|
||||
API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Suspend Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Agreement $suspendedAgreement */</span>
|
||||
<span class="hljs-variable">$suspendedAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'SuspendBillingAgreement.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">AgreementStateDescriptor</span>;
|
||||
|
||||
<span class="hljs-comment">//Create an Agreement State Descriptor, explaining the reason to suspend.</span>
|
||||
<span class="hljs-variable">$agreementStateDescriptor</span> = <span class="hljs-keyword">new</span> AgreementStateDescriptor();
|
||||
<span class="hljs-variable">$agreementStateDescriptor</span>->setNote(<span class="hljs-string">"Reactivating the agreement"</span>);
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
|
||||
<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">exit</span>(<span class="hljs-number">1</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">$agreement</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|
||||
26
sample/doc/billing/SuspendBillingAgreement.html
Normal file
26
sample/doc/billing/SuspendBillingAgreement.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/SuspendBillingAgreement</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="billing/SuspendBillingAgreement"><meta name="groc-project-path" content="billing/SuspendBillingAgreement.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">billing/SuspendBillingAgreement.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="suspend-an-agreement">Suspend an agreement</h1>
|
||||
<p>This sample code demonstrate how you can suspend a billing agreement, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement</a>
|
||||
API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Agreement $createdAgreement */</span>
|
||||
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBillingAgreementWithCreditCard.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">AgreementStateDescriptor</span>;
|
||||
|
||||
<span class="hljs-comment">//Create an Agreement State Descriptor, explaining the reason to suspend.</span>
|
||||
<span class="hljs-variable">$agreementStateDescriptor</span> = <span class="hljs-keyword">new</span> AgreementStateDescriptor();
|
||||
<span class="hljs-variable">$agreementStateDescriptor</span>->setNote(<span class="hljs-string">"Suspending the agreement"</span>);
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
|
||||
<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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Suspended the Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$agreementStateDescriptor</span>, <span class="hljs-variable">$agreement</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|
||||
38
sample/doc/billing/UpdateBillingAgreement.html
Normal file
38
sample/doc/billing/UpdateBillingAgreement.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/UpdateBillingAgreement</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="billing/UpdateBillingAgreement"><meta name="groc-project-path" content="billing/UpdateBillingAgreement.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">billing/UpdateBillingAgreement.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="update-an-agreement">Update an agreement</h1>
|
||||
<p>This sample code demonstrate how you can update a billing agreement, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement</a>
|
||||
API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Agreement $createdAgreement */</span>
|
||||
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBillingAgreementWithCreditCard.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PatchRequest</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</span>;
|
||||
|
||||
<span class="hljs-variable">$patch</span> = <span class="hljs-keyword">new</span> Patch();
|
||||
|
||||
<span class="hljs-variable">$patch</span>->setOp(<span class="hljs-string">'replace'</span>)
|
||||
->setPath(<span class="hljs-string">'/'</span>)
|
||||
->setValue(json_decode(<span class="hljs-string">'{
|
||||
"description": "New Description",
|
||||
"shipping_address": {
|
||||
"line1": "2065 Hamilton Ave",
|
||||
"city": "San Jose",
|
||||
"state": "CA",
|
||||
"postal_code": "95125",
|
||||
"country_code": "US"
|
||||
}
|
||||
}'</span>));
|
||||
<span class="hljs-variable">$patchRequest</span> = <span class="hljs-keyword">new</span> PatchRequest();
|
||||
<span class="hljs-variable">$patchRequest</span>->addPatch(<span class="hljs-variable">$patch</span>);
|
||||
<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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Updated the Agreement with new Description and Updated Shipping Address"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$agreement</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>
|
||||
37
sample/doc/billing/UpdatePlan.html
Normal file
37
sample/doc/billing/UpdatePlan.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/UpdatePlan</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="billing/UpdatePlan"><meta name="groc-project-path" content="billing/UpdatePlan.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">billing/UpdatePlan.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="update-a-plan">Update a plan</h1>
|
||||
<p>This sample code demonstrate how you can update a billing plan, as documented here at:
|
||||
<a href="https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan">https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan</a>
|
||||
API used: /v1/payments/billing-plans/<Plan-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="making-plan-active">Making Plan Active</h3>
|
||||
<p>This example demonstrate how you could activate the Plan.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan object from Create Plan Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> Plan $createdPlan */</span>
|
||||
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePlan.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Plan</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PatchRequest</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Common</span>\<span class="hljs-title">PPModel</span>;
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$patch</span> = <span class="hljs-keyword">new</span> Patch();
|
||||
|
||||
<span class="hljs-variable">$value</span> = <span class="hljs-keyword">new</span> PPModel(<span class="hljs-string">'{
|
||||
"state":"ACTIVE"
|
||||
}'</span>);
|
||||
|
||||
<span class="hljs-variable">$patch</span>->setOp(<span class="hljs-string">'replace'</span>)
|
||||
->setPath(<span class="hljs-string">'/'</span>)
|
||||
->setValue(<span class="hljs-variable">$value</span>);
|
||||
<span class="hljs-variable">$patchRequest</span> = <span class="hljs-keyword">new</span> PatchRequest();
|
||||
<span class="hljs-variable">$patchRequest</span>->addPatch(<span class="hljs-variable">$patch</span>);
|
||||
|
||||
<span class="hljs-variable">$createdPlan</span>->update(<span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$apiContext</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">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Updated the Plan to Active State"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>->getId(), <span class="hljs-variable">$patchRequest</span>, <span class="hljs-variable">$plan</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$plan</span>;</div></div></div></div></body></html>
|
||||
@@ -30,15 +30,4 @@ notification object
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Cancel Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Cancel Invoice:</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoice</span>->toJSON(128); <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">"Cancel Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-variable">$invoice</span>->getId(), <span class="hljs-variable">$notify</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>
|
||||
@@ -69,7 +69,7 @@ detailed breakdown of invoice</p></div></div><div class="code"><div class="wrapp
|
||||
->setCity(<span class="hljs-string">"Portland"</span>)
|
||||
->setState(<span class="hljs-string">"OR"</span>)
|
||||
->setPostalCode(<span class="hljs-string">"97217"</span>)
|
||||
->setCountryCode(<span class="hljs-string">"US"</span>);
|
||||
->setCountryCode(<span class="hljs-string">"US"</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">$invoice</span>;
|
||||
|
||||
<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
|
||||
@@ -79,17 +79,5 @@ with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)<
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Invoice Creation</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created Invoice:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoice</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">$invoice</span>->toJSON(128); <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">"Invoice Creation"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-variable">$invoice</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$invoice</span>);</div></div></div></div></body></html>
|
||||
@@ -15,14 +15,5 @@ Invoice ID
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice details</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Invoice: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoiceId</span>;<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoice</span>->toJSON(128); <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 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">$invoice</span>);</div></div></div></div></body></html>
|
||||
@@ -13,14 +13,4 @@ Refer the method doc for valid values for keys
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got invoices </div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoices</span>->toJSON(128); <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">"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>
|
||||
@@ -29,15 +29,4 @@ notification object
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Remind Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Remind Invoice:</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoice</span>->toJSON(128); <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">"Remind Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$notify</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>
|
||||
@@ -18,14 +18,4 @@ with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)<
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Send Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Send Invoice:</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$invoice</span>->toJSON(128); <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">"Send Invoice"</span>, <span class="hljs-string">"Invoice"</span>, <span class="hljs-variable">$invoice</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>
|
||||
@@ -12,4 +12,4 @@
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-variable">$tokenInfo</span>->getAccessToken(), <span class="hljs-variable">$tokenInfo</span>);</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-variable">$tokenInfo</span>->getAccessToken(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$tokenInfo</span>);</div></div></div></div></body></html>
|
||||
@@ -22,4 +22,4 @@ to retreive the information. The short lived access token can be retrieved using
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<span class="hljs-string">"User Information"</span>, <span class="hljs-string">"User Info"</span>, <span class="hljs-variable">$userInfo</span>->getUserId(), <span class="hljs-variable">$userInfo</span>->toJSON(128));</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"User Information"</span>, <span class="hljs-string">"User Info"</span>, <span class="hljs-variable">$userInfo</span>->getUserId(), <span class="hljs-variable">$params</span>, <span class="hljs-variable">$userInfo</span>);</div></div></div></div></body></html>
|
||||
@@ -15,4 +15,4 @@
|
||||
<span class="hljs-variable">$apiContext</span>
|
||||
);
|
||||
|
||||
print_result(<span class="hljs-string">"Generated the User Consent URL"</span>, <span class="hljs-string">"URL"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-string">'<a href="'</span>. <span class="hljs-variable">$redirectUrl</span> . <span class="hljs-string">'" >Click Here to Obtain User Consent</a>'</span>);</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Generated the User Consent URL"</span>, <span class="hljs-string">"URL"</span>, <span class="hljs-string">'<a href="'</span>. <span class="hljs-variable">$redirectUrl</span> . <span class="hljs-string">'" >Click Here to Obtain User Consent</a>'</span>, <span class="hljs-variable">$baseUrl</span>, <span class="hljs-variable">$redirectUrl</span>);</div></div></div></div></body></html>
|
||||
@@ -18,6 +18,6 @@ The user would then able to retrieve the access token by getting the code, which
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<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">$accessToken</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>);
|
||||
|
||||
}</div></div></div></div></body></html>
|
||||
File diff suppressed because one or more lines are too long
@@ -17,4 +17,4 @@ that contains the web profile ID.</p></div></div><div class="code"><div class="w
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<span class="hljs-string">"Deleted Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$createProfileResponse</span>->getId());</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<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-keyword">null</span>);</div></div></div></div></body></html>
|
||||
@@ -16,6 +16,6 @@ that contains the web profile ID.</p></div></div><div class="code"><div class="w
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<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-variable">$webProfile</span>);
|
||||
ResultPrinter::printResult(<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">$webProfile</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$webProfile</span>;</div></div></div></div></body></html>
|
||||
@@ -15,9 +15,9 @@ static <code>get_list</code> method on the WebProfile class.
|
||||
}
|
||||
<span class="hljs-variable">$result</span> = <span class="hljs-string">''</span>;
|
||||
<span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$list</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$object</span>) {
|
||||
<span class="hljs-variable">$result</span> .= <span class="hljs-variable">$object</span>->toJSON(128) . PHP_EOL;
|
||||
<span class="hljs-variable">$result</span> .= <span class="hljs-variable">$object</span>->toJSON(<span class="hljs-number">128</span>) . PHP_EOL;
|
||||
}
|
||||
|
||||
print_result(<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-variable">$result</span>);
|
||||
ResultPrinter::printResult(<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">$result</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$list</span>;</div></div></div></div></body></html>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$list</span>;</div></div></div></div></body></html>
|
||||
@@ -26,4 +26,4 @@ as shown below</p></div></div><div class="code"><div class="wrapper"><span class
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<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">$webProfile</span>);</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<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">$webProfile</span>);</div></div></div></div></body></html>
|
||||
@@ -16,4 +16,4 @@ object</p></div></div><div class="code"><div class="wrapper"> <span class
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
print_result(<span class="hljs-string">"Updated Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$updatedWebProfile</span>->getId(), <span class="hljs-variable">$updatedWebProfile</span>);</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Updated Web Profile"</span>, <span class="hljs-string">"Web Profile"</span>, <span class="hljs-variable">$updatedWebProfile</span>->getId(), <span class="hljs-variable">$webProfile</span>, <span class="hljs-variable">$updatedWebProfile</span>);</div></div></div></div></body></html>
|
||||
@@ -33,7 +33,7 @@ createAuthorization defined in common.php</p></div></div><div class="code"><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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -61,7 +61,7 @@ Please note that currently future payments works only with PayPal as a funding i
|
||||
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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -91,7 +91,7 @@ The return object contains the state.</p></div></div><div class="code"><div clas
|
||||
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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -9,8 +9,7 @@ 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">RedirectUrls</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>;
|
||||
session_start();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payer">Payer</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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||
<p>A resource representing a Payer that funds a payment
|
||||
For paypal account payments, set payment method
|
||||
to 'paypal'.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
|
||||
@@ -77,14 +76,7 @@ method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-k
|
||||
<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>
|
||||
<p>Save the payment id so that you can 'complete' the payment
|
||||
once the buyer approves the payment and is redirected
|
||||
back to your website.
|
||||
It is not a great idea to store the payment id
|
||||
in the session. In a real world app, you may want to
|
||||
store the payment id in a database.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$_SESSION</span>[<span class="hljs-string">'paymentId'</span>] = <span class="hljs-variable">$payment</span>->getId();
|
||||
<span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$redirectUrl</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>
|
||||
@@ -80,7 +80,7 @@ The return object contains the state.</p></div></div><div class="code"><div clas
|
||||
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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -8,26 +8,24 @@ API used: POST '/v1/payments/payment/<payment-id>/execute'.</p></div></d
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ExecutePayment</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">PaymentExecution</span>;
|
||||
session_start();
|
||||
<span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
payment id was previously stored in session in
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$paymentId</span> = <span class="hljs-variable">$_SESSION</span>[<span class="hljs-string">'paymentId'</span>];
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||
to execute a PayPal account payment.
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$paymentId</span> = <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'paymentId'</span>];
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||
to execute a PayPal account payment.
|
||||
The payer_id is added to the request query parameters
|
||||
when the user is redirected from paypal back to your site</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$execution</span> = <span class="hljs-keyword">new</span> PaymentExecution();
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);
|
||||
|
||||
<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>);
|
||||
when the user is redirected from paypal back to your site</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$execution</span> = <span class="hljs-keyword">new</span> PaymentExecution();
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);
|
||||
|
||||
<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(128);
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"</pre><a href='../index.html'>Back</a></body></html>"</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>;
|
||||
|
||||
} <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">"User cancelled payment."</span>;
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"</h1><a href='../index.html'>Back</a></body></html>"</span>;
|
||||
}</div></div></div></div></body></html>
|
||||
}</div></div></div></div></body></html>
|
||||
@@ -25,7 +25,7 @@ createAuthorization is defined in common.php</p></div></div><div class="code"><d
|
||||
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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -41,7 +41,7 @@ with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)<
|
||||
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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -27,7 +27,7 @@ Payment ID
|
||||
</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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -26,7 +26,7 @@ Refer the method doc for valid values for keys
|
||||
</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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -30,8 +30,8 @@ has expired.</p></div></div><div class="code"><div class="wrapper"><span class="
|
||||
<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(128);<span class="hljs-preprocessor">?></span>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -46,7 +46,7 @@ PayPal-Request-Id (idempotency) header for this resource</p></div></div><div cla
|
||||
</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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -22,7 +22,7 @@ createAuthorization is defined in common.php</p></div></div><div class="code"><d
|
||||
<div>
|
||||
Voided authorization
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$voidedAuth</span>->toJSON(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -22,7 +22,7 @@ transaction from your payment resource.</p></div></div><div class="code"><div cl
|
||||
</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(128)<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -32,7 +32,7 @@ given sale transaction id.</p></div></div><div class="code"><div class="wrapper"
|
||||
</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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -31,7 +31,7 @@ in future payments.
|
||||
</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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
@@ -21,7 +21,7 @@ card operation. Use $card->getId()</p></div></div><div class="code"><div clas
|
||||
</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(128);<span class="hljs-preprocessor">?></span></pre>
|
||||
<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>
|
||||
</html></div></div></div></div></body></html>
|
||||
82
sample/header.html
Normal file
82
sample/header.html
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<link rel="icon" href="images/favicon.ico">
|
||||
|
||||
<title>PayPal REST API Samples</title>
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
pre {
|
||||
overflow-y: auto;
|
||||
overflow-wrap: normal;
|
||||
}
|
||||
.panel-default>.panel-heading {
|
||||
color: #FFF;
|
||||
background-color: #428bca;
|
||||
border-color: #428bca;
|
||||
}
|
||||
/*
|
||||
.string { color: green; }
|
||||
.number { color: darkorange; }
|
||||
.boolean { color: blue; }
|
||||
.null { color: magenta; }
|
||||
.key { color: red; }
|
||||
*/
|
||||
</style>
|
||||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/scrollspy.min.js"></script>
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
$("#accordion .panel-collapse:last").collapse('toggle');
|
||||
|
||||
/*
|
||||
|
||||
$(".prettyprint").each(function() {
|
||||
$(this).html(syntaxHighlight($(this).html()));
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
|
||||
/* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript
|
||||
function syntaxHighlight(json) {
|
||||
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
|
||||
var cls = 'number';
|
||||
if (/^"/.test(match)) {
|
||||
if (/:$/.test(match)) {
|
||||
cls = 'key';
|
||||
} else {
|
||||
cls = 'string';
|
||||
}
|
||||
} else if (/true|false/.test(match)) {
|
||||
cls = 'boolean';
|
||||
} else if (/null/.test(match)) {
|
||||
cls = 'null';
|
||||
}
|
||||
return '<span class="' + cls + '">' + match + '</span>';
|
||||
});
|
||||
}
|
||||
*/
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@@ -36,19 +36,17 @@
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<h1> REST API Samples</h1>
|
||||
<p>These examples are created to experiment with the rest-api-sdk-php capabilities. Each examples are designed to demonstrate the default use-cases in each segment.
|
||||
<p>These examples are created to experiment with the PayPal-PHP-SDK capabilities. Each examples are designed to demonstrate the default use-cases in each segment.
|
||||
Many examples should be executable, and should allow you to experience the default behavior of our sdk, to expedite your integration experience.</p>
|
||||
<p>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<div class="container">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Payments</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#payments" target="_blank">Payments</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
@@ -111,7 +109,7 @@
|
||||
|
||||
<div class="panel panel-primary" >
|
||||
<div class="panel-heading" >
|
||||
<h3 class="panel-title">Sale</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#sale-transactions" target="_blank">Sale</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
@@ -136,9 +134,108 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-primary" >
|
||||
<div class="panel-heading" >
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#billing-plans-and-agreements" target="_blank">Billing Plan & Agreements</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-9 "><h5>Create Billing Plan</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/CreatePlan.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/CreatePlan.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 Billing Plan</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/GetPlan.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/GetPlan.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>Update/Activate Plan</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/UpdatePlan.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/UpdatePlan.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>List Billing Plans</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/ListPlans.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/ListPlans.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>Create Billing Agreement With Credit Card</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/CreateBillingAgreementWithCreditCard.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/CreateBillingAgreementWithCreditCard.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>Create Billing Agreement With PayPal</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/CreateBillingAgreementWithPayPal.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/CreateBillingAgreementWithPayPal.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 Billing Agreement</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/GetBillingAgreement.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/GetBillingAgreement.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>Update Billing Agreement</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/UpdateBillingAgreement.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/UpdateBillingAgreement.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>Suspend Billing Agreement</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/SuspendBillingAgreement.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/SuspendBillingAgreement.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>Reactivate Billing Agreement</h5></div>
|
||||
<div class="col-md-3">
|
||||
<a href="billing/ReactivateBillingAgreement.php" class="btn btn-primary pull-left" >Execute <i class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/billing/ReactivateBillingAgreement.html" class="btn btn-default pull-right" >Source <i class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Vault</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#vault" target="_blank">Vault</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
@@ -174,7 +271,7 @@
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Authorization and capture</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#authorizations" target="_blank">Authorization and capture</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
@@ -237,7 +334,7 @@
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Payment Experience</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#payment-experience" target="_blank">Payment Experience</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
@@ -300,7 +397,7 @@
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Invoice</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#invoicing" target="_blank">Invoice</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
@@ -363,7 +460,7 @@
|
||||
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Identity (LIPP)</h3>
|
||||
<h3 class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#identity" target="_blank">Identity (LIPP)</a></h3>
|
||||
</div>
|
||||
<!-- List group -->
|
||||
<ul class="list-group">
|
||||
|
||||
@@ -43,15 +43,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Cancel Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Cancel Invoice:</div>
|
||||
<pre><?php echo $invoice->toJSON(128); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Cancel Invoice", "Invoice", $invoice->getId(), $notify, null);
|
||||
|
||||
@@ -93,6 +93,9 @@ $invoice->getShippingInfo()->getAddress()
|
||||
->setPostalCode("97217")
|
||||
->setCountryCode("US");
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $invoice;
|
||||
|
||||
try {
|
||||
// ### Create Invoice
|
||||
// Create an invoice by calling the invoice->create() method
|
||||
@@ -103,17 +106,6 @@ try {
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Invoice Creation</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created Invoice:
|
||||
<?php echo $invoice->getId(); ?>
|
||||
</div>
|
||||
<pre><?php echo $invoice->toJSON(128); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Invoice Creation", "Invoice", $invoice->getId(), $request, $invoice);
|
||||
|
||||
|
||||
@@ -22,14 +22,5 @@ try {
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice details</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Invoice: <?php echo $invoiceId;?></div>
|
||||
<pre><?php echo $invoice->toJSON(128); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $invoice);
|
||||
|
||||
@@ -19,14 +19,4 @@ try {
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got invoices </div>
|
||||
<pre><?php echo $invoices->toJSON(128); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices);
|
||||
|
||||
@@ -41,15 +41,5 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
?>
|
||||
ResultPrinter::printResult("Remind Invoice", "Invoice", null, $notify, null);
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Remind Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Remind Invoice:</div>
|
||||
<pre><?php echo $invoice->toJSON(128); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -27,14 +27,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Send Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Send Invoice:</div>
|
||||
<pre><?php echo $invoice->toJSON(128); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Send Invoice", "Invoice", $invoice->getId(), null, null);
|
||||
|
||||
@@ -19,4 +19,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), $tokenInfo);
|
||||
ResultPrinter::printResult("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), null, $tokenInfo);
|
||||
|
||||
@@ -34,4 +34,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("User Information", "User Info", $userInfo->getUserId(), $userInfo->toJSON(128));
|
||||
ResultPrinter::printResult("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo);
|
||||
|
||||
@@ -19,4 +19,4 @@ $redirectUrl = PPOpenIdSession::getAuthorizationUrl(
|
||||
$apiContext
|
||||
);
|
||||
|
||||
print_result("Generated the User Consent URL", "URL", null, '<a href="'. $redirectUrl . '" >Click Here to Obtain User Consent</a>');
|
||||
ResultPrinter::printResult("Generated the User Consent URL", "URL", '<a href="'. $redirectUrl . '" >Click Here to Obtain User Consent</a>', $baseUrl, $redirectUrl);
|
||||
|
||||
@@ -23,6 +23,6 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $accessToken);
|
||||
ResultPrinter::printResult("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $_GET['code'], $accessToken);
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
|
||||
// Parameters for style and presentation.
|
||||
->setPresentation($presentation);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $webProfile;
|
||||
|
||||
try {
|
||||
// Use this call to create a profile.
|
||||
$createProfileResponse = $webProfile->create($apiContext);
|
||||
@@ -55,6 +58,6 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $createProfileResponse);
|
||||
ResultPrinter::printResult("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $request, $createProfileResponse);
|
||||
|
||||
return $createProfileResponse;
|
||||
|
||||
@@ -27,4 +27,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Deleted Web Profile", "Web Profile", $createProfileResponse->getId());
|
||||
ResultPrinter::printResult("Deleted Web Profile", "Web Profile", $createProfileResponse->getId(), null, null);
|
||||
|
||||
@@ -23,6 +23,6 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Get Web Profile", "Web Profile", $webProfile->getId(), $webProfile);
|
||||
ResultPrinter::printResult("Get Web Profile", "Web Profile", $webProfile->getId(), null, $webProfile);
|
||||
|
||||
return $webProfile;
|
||||
|
||||
@@ -23,6 +23,6 @@ foreach ($list as $object) {
|
||||
$result .= $object->toJSON(128) . PHP_EOL;
|
||||
}
|
||||
|
||||
print_result("Get List of All Web Profiles", "Web Profiles", null, $result);
|
||||
ResultPrinter::printResult("Get List of All Web Profiles", "Web Profiles", null, null, $result);
|
||||
|
||||
return $list;
|
||||
|
||||
@@ -45,4 +45,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile);
|
||||
ResultPrinter::printResult("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $webProfile);
|
||||
|
||||
@@ -29,4 +29,4 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $updatedWebProfile);
|
||||
ResultPrinter::printResult("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $webProfile, $updatedWebProfile);
|
||||
|
||||
@@ -14,7 +14,6 @@ use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
session_start();
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
@@ -111,14 +110,6 @@ foreach($payment->getLinks() as $link) {
|
||||
}
|
||||
|
||||
// ### Redirect buyer to PayPal website
|
||||
// Save the payment id so that you can 'complete' the payment
|
||||
// once the buyer approves the payment and is redirected
|
||||
// back to your website.
|
||||
//
|
||||
// It is not a great idea to store the payment id
|
||||
// in the session. In a real world app, you may want to
|
||||
// store the payment id in a database.
|
||||
$_SESSION['paymentId'] = $payment->getId();
|
||||
if(isset($redirectUrl)) {
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
|
||||
@@ -11,32 +11,32 @@ require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\ExecutePayment;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\PaymentExecution;
|
||||
session_start();
|
||||
if(isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
// Get the payment Object by passing paymentId
|
||||
// payment id was previously stored in session in
|
||||
// CreatePaymentUsingPayPal.php
|
||||
$paymentId = $_SESSION['paymentId'];
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
|
||||
// PaymentExecution object includes information necessary
|
||||
// to execute a PayPal account payment.
|
||||
// The payer_id is added to the request query parameters
|
||||
// when the user is redirected from paypal back to your site
|
||||
$execution = new PaymentExecution();
|
||||
$execution->setPayerId($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$result = $payment->execute($execution, $apiContext);
|
||||
|
||||
if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
// Get the payment Object by passing paymentId
|
||||
// payment id was previously stored in session in
|
||||
// CreatePaymentUsingPayPal.php
|
||||
$paymentId = $_GET['paymentId'];
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
|
||||
// PaymentExecution object includes information necessary
|
||||
// to execute a PayPal account payment.
|
||||
// The payer_id is added to the request query parameters
|
||||
// when the user is redirected from paypal back to your site
|
||||
$execution = new PaymentExecution();
|
||||
$execution->setPayerId($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
// (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>";
|
||||
|
||||
echo $result->toJSON(128);
|
||||
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||
|
||||
} else {
|
||||
echo "<html><body><h1>";
|
||||
echo "User cancelled payment.";
|
||||
echo "User cancelled payment.";
|
||||
echo "</h1><a href='../index.html'>Back</a></body></html>";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user