recreate project
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
<?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\CreditCard;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\PayerInfo;
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Api\ShippingAddress;
|
||||
|
||||
/* 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('2019-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(array('email' => 'jaypatel512-facilitator@hotmail.com')));
|
||||
|
||||
// Add Credit Card to Funding Instruments
|
||||
$creditCard = new CreditCard();
|
||||
$creditCard->setType('visa')
|
||||
->setNumber('4491759698858890')
|
||||
->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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $agreement);
|
||||
|
||||
return $agreement;
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?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\Payer;
|
||||
use PayPal\Api\Plan;
|
||||
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('2019-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->getApprovalLink()
|
||||
// method
|
||||
$approvalUrl = $agreement->getApprovalLink();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Created Billing Agreement. Please visit the URL to Approve.", "Agreement", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $agreement);
|
||||
|
||||
return $agreement;
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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\ChargeModel;
|
||||
use PayPal\Api\Currency;
|
||||
use PayPal\Api\MerchantPreferences;
|
||||
use PayPal\Api\PaymentDefinition;
|
||||
use PayPal\Api\Plan;
|
||||
|
||||
// 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(array('value' => 100, 'currency' => 'USD')));
|
||||
|
||||
// Charge Models
|
||||
$chargeModel = new ChargeModel();
|
||||
$chargeModel->setType('SHIPPING')
|
||||
->setAmount(new Currency(array('value' => 10, 'currency' => 'USD')));
|
||||
|
||||
$paymentDefinition->setChargeModels(array($chargeModel));
|
||||
|
||||
$merchantPreferences = new MerchantPreferences();
|
||||
$baseUrl = getBaseUrl();
|
||||
// ReturnURL and CancelURL are not required and used when creating billing agreement with payment_method as "credit_card".
|
||||
// However, it is generally a good idea to set these values, in case you plan to create billing agreements which accepts "paypal" as payment_method.
|
||||
// This will keep your plan compatible with both the possible scenarios on how it is being used in agreement.
|
||||
$merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true")
|
||||
->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false")
|
||||
->setAutoBillAmount("yes")
|
||||
->setInitialFailAmountAction("CONTINUE")
|
||||
->setMaxFailAttempts("0")
|
||||
->setSetupFee(new Currency(array('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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Created Plan", "Plan", $output->getId(), $request, $output);
|
||||
|
||||
return $output;
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// # Delete Plan Sample
|
||||
//
|
||||
// This sample code demonstrate how you can delete 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 {
|
||||
$result = $createdPlan->delete($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Deleted a Plan", "Plan", $createdPlan->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Deleted a Plan", "Plan", $createdPlan->getId(), null, null);
|
||||
|
||||
return $createdPlan;
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// #Execute Agreement
|
||||
// This is the second part of CreateAgreement Sample.
|
||||
// Use this call to execute an agreement after the buyer approves it
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
// ## Approval Status
|
||||
// Determine if the user accepted or denied the request
|
||||
if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
$token = $_GET['token'];
|
||||
$agreement = new \PayPal\Api\Agreement();
|
||||
try {
|
||||
// ## Execute Agreement
|
||||
// Execute the agreement by passing in the token
|
||||
$agreement->execute($token, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);
|
||||
|
||||
// ## Get Agreement
|
||||
// Make a get call to retrieve the executed agreement details
|
||||
try {
|
||||
$agreement = \PayPal\Api\Agreement::get($agreement->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Agreement", "Agreement", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Agreement", "Agreement", $agreement->getId(), null, $agreement);
|
||||
|
||||
} else {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("User Cancelled the Approval", null);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $agreement);
|
||||
|
||||
return $agreement;
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Retrieved a Plan", "Plan", $plan->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Retrieved a Plan", "Plan", $plan->getId(), null, $plan);
|
||||
|
||||
return $plan;
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("List of Plans", "Plan", null, $params, $planList);
|
||||
|
||||
return $planList;
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $agreement);
|
||||
|
||||
return $agreement;
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
// # Search Billing Transactions Sample
|
||||
//
|
||||
// This sample code demonstrate how you can search all billing transactions, as documented here at:
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#search-for-transactions
|
||||
// API used: GET /v1/payments/billing-agreements/<Agreement-Id>/transactions? start-date=yyyy-mm-dd&end-date=yyyy-mm-dd
|
||||
|
||||
// Retrieving the Agreement object from Get Billing Agreement. This may not be necessary if you are trying to search for transactions of already created Agreement.
|
||||
/** @var Agreement $agreement */
|
||||
$agreement = require 'GetBillingAgreement.php';
|
||||
|
||||
// Replace this with your AgreementId to search transactions based on your agreement.
|
||||
$agreementId = $agreement->getId();
|
||||
|
||||
use PayPal\Api\Agreement;
|
||||
|
||||
// Adding Params to search transaction within a given time frame.
|
||||
$params = array('start_date' => date('Y-m-d', strtotime('-15 years')), 'end_date' => date('Y-m-d', strtotime('+5 days')));
|
||||
|
||||
try {
|
||||
$result = Agreement::searchTransactions($agreementId, $params, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Search for Transactions", "AgreementTransaction", $agreementId, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Search for Transactions", "AgreementTransaction", $agreementId, $params, $result);
|
||||
|
||||
return $agreement;
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Suspended the Agreement", "Agreement", null, $agreementStateDescriptor, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Suspended the Agreement", "Agreement", $agreement->getId(), $agreementStateDescriptor, $agreement);
|
||||
|
||||
return $agreement;
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\Patch;
|
||||
use PayPal\Api\PatchRequest;
|
||||
|
||||
$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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", null, $patchRequest, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", $agreement->getId(), $patchRequest, $agreement);
|
||||
|
||||
return $agreement;
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\Patch;
|
||||
use PayPal\Api\PatchRequest;
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Common\PayPalModel;
|
||||
|
||||
try {
|
||||
$patch = new Patch();
|
||||
|
||||
$value = new PayPalModel('{
|
||||
"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 (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Updated the Plan to Active State", "Plan", null, $patchRequest, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Updated the Plan to Active State", "Plan", $plan->getId(), $patchRequest, $plan);
|
||||
|
||||
return $plan;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?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>
|
||||
|
||||
// ### Changing Plan Amount
|
||||
// This example demonstrate how you could change the plan amount
|
||||
|
||||
// Retrieving the Plan object from Create Plan Sample to demonstrate the List
|
||||
/** @var Plan $createdPlan */
|
||||
$createdPlan = require 'CreatePlan.php';
|
||||
|
||||
use PayPal\Api\Patch;
|
||||
use PayPal\Api\PatchRequest;
|
||||
use PayPal\Api\Plan;
|
||||
|
||||
try {
|
||||
$patch = new Patch();
|
||||
|
||||
$paymentDefinitions = $createdPlan->getPaymentDefinitions();
|
||||
$paymentDefinitionId = $paymentDefinitions[0]->getId();
|
||||
$patch->setOp('replace')
|
||||
->setPath('/payment-definitions/' . $paymentDefinitionId)
|
||||
->setValue(json_decode(
|
||||
'{
|
||||
"name": "Updated Payment Definition",
|
||||
"frequency": "Day",
|
||||
"amount": {
|
||||
"currency": "USD",
|
||||
"value": "50"
|
||||
}
|
||||
}'
|
||||
));
|
||||
$patchRequest = new PatchRequest();
|
||||
$patchRequest->addPatch($patch);
|
||||
|
||||
$createdPlan->update($patchRequest, $apiContext);
|
||||
|
||||
$plan = Plan::get($createdPlan->getId(), $apiContext);
|
||||
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Updated the Plan Payment Definition", "Plan", null, $patchRequest, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Updated the Plan Payment Definition", "Plan", $plan->getId(), $patchRequest, $plan);
|
||||
|
||||
return $plan;
|
||||
Reference in New Issue
Block a user