forked from LiveCarta/PayPal-PHP-SDK
Enabled Payment Experience
- Updated Api to enabled Payment Experience - Updated Tests and Samples - Added Json Validator - Ability for PPModel to return array of self objects
This commit is contained in:
60
sample/payment-experience/CreateWebProfile.php
Normal file
60
sample/payment-experience/CreateWebProfile.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
// ### Create Web Profile
|
||||
// Use the /web-profiles resource to create seamless payment experience profiles. See the payment experience overview for further information about using the /payment resource to create the PayPal payment and pass the experience_profile_id.
|
||||
// Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#create-a-web-experience-profile
|
||||
|
||||
// Lets create an instance of FlowConfig and add
|
||||
// landing page type information
|
||||
$flowConfig = new \PayPal\Api\FlowConfig();
|
||||
// Type of PayPal page to be displayed when a user lands on the PayPal site for checkout. Allowed values: Billing or Login. When set to Billing, the Non-PayPal account landing page is used. When set to Login, the PayPal account login landing page is used.
|
||||
$flowConfig->setLandingPageType("Billing");
|
||||
// The URL on the merchant site for transferring to after a bank transfer payment.
|
||||
$flowConfig->setBankTxnPendingUrl("http://www.yeowza.com/");
|
||||
|
||||
// Parameters for style and presentation.
|
||||
$presentation = new \PayPal\Api\Presentation();
|
||||
|
||||
// A URL to logo image. Allowed vaues: .gif, .jpg, or .png.
|
||||
$presentation->setLogoImage("http://www.yeowza.com/favico.ico")
|
||||
// A label that overrides the business name in the PayPal account on the PayPal pages.
|
||||
->setBrandName("YeowZa! Paypal")
|
||||
// Locale of pages displayed by PayPal payment experience.
|
||||
->setLocaleCode("US");
|
||||
|
||||
// Parameters for input fields customization.
|
||||
$inputFields = new \PayPal\Api\InputFields();
|
||||
// Enables the buyer to enter a note to the merchant on the PayPal page during checkout.
|
||||
$inputFields->setAllowNote(true)
|
||||
// Determines whether or not PayPal displays shipping address fields on the experience pages. Allowed values: 0, 1, or 2. When set to 0, PayPal displays the shipping address on the PayPal pages. When set to 1, PayPal does not display shipping address fields whatsoever. When set to 2, if you do not pass the shipping address, PayPal obtains it from the buyer’s account profile. For digital goods, this field is required, and you must set it to 1.
|
||||
->setNoShipping(1)
|
||||
// Determines whether or not the PayPal pages should display the shipping address and not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. Allowed values: 0 or 1. When set to 0, the PayPal pages should not display the shipping address. When set to 1, the PayPal pages should display the shipping address.
|
||||
->setAddressOverride(0);
|
||||
|
||||
// #### Payment Web experience profile resource
|
||||
$webProfile = new \PayPal\Api\WebProfile();
|
||||
|
||||
// Name of the web experience profile. Required. Must be unique
|
||||
$webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
|
||||
// Parameters for flow configuration.
|
||||
->setFlowConfig($flowConfig)
|
||||
// Parameters for style and presentation.
|
||||
->setPresentation($presentation);
|
||||
|
||||
try {
|
||||
// Use this call to create a profile.
|
||||
$createProfileResponse = $webProfile->create($apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $createProfileResponse);
|
||||
|
||||
return $createProfileResponse;
|
||||
30
sample/payment-experience/DeleteWebProfile.php
Normal file
30
sample/payment-experience/DeleteWebProfile.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// #### Delete Web Profile
|
||||
// Use this call to delete a web experience profile.
|
||||
// Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#delete-a-web-experience-profile
|
||||
|
||||
// We are going to re-use the sample code from CreateWebProfile.php.
|
||||
// If you have not visited the sample yet, please visit it before trying GetWebProfile.php
|
||||
// The CreateWebProfile.php will create a web profile for us, and return a CreateProfileResponse,
|
||||
// that contains the web profile ID.
|
||||
/** @var \PayPal\Api\CreateProfileResponse $result */
|
||||
$createProfileResponse = require_once 'CreateWebProfile.php';
|
||||
|
||||
// Create a new instance of web Profile ID, and set the ID.
|
||||
$webProfile = new \PayPal\Api\WebProfile();
|
||||
$webProfile->setId($createProfileResponse->getId());
|
||||
|
||||
try {
|
||||
// Execute the delete method
|
||||
$webProfile->delete($apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Deleted Web Profile", "Web Profile", $createProfileResponse->getId());
|
||||
28
sample/payment-experience/GetWebProfile.php
Normal file
28
sample/payment-experience/GetWebProfile.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
// ### Get Web Profile
|
||||
// If your request is successful, the API returns a web_profile object response that contains the profile details.
|
||||
// Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-web-experience-profile
|
||||
|
||||
// We are going to re-use the sample code from CreateWebProfile.php.
|
||||
// If you have not visited the sample yet, please visit it before trying GetWebProfile.php
|
||||
// The CreateWebProfile.php will create a web profile for us, and return a CreateProfileResponse,
|
||||
// that contains the web profile ID.
|
||||
/** @var \PayPal\Api\CreateProfileResponse $result */
|
||||
$createProfileResponse = require 'CreateWebProfile.php';
|
||||
|
||||
try {
|
||||
// If your request is successful, the API returns a web_profile object response that contains the profile details.
|
||||
$webProfile = \PayPal\Api\WebProfile::get($createProfileResponse->getId(), $apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Get Web Profile", "Web Profile", $webProfile->getId(), $webProfile);
|
||||
|
||||
return $webProfile;
|
||||
28
sample/payment-experience/ListWebProfiles.php
Normal file
28
sample/payment-experience/ListWebProfiles.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
$apiContext = require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
// ### Retrieve List of All Web Profiles
|
||||
// Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#list-web-experience-profiles
|
||||
|
||||
// Retrieve the list of all web profiles by calling the
|
||||
// static `get_list` method on the WebProfile class.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$list = \PayPal\Api\WebProfile::get_list($apiContext);
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
$result = '';
|
||||
foreach ($list as $object) {
|
||||
$result .= $object->toJSON(JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
}
|
||||
|
||||
print_result("Get List of All Web Profiles", "Web Profiles", null, $result);
|
||||
|
||||
return $list;
|
||||
48
sample/payment-experience/PartiallyUpdateWebProfile.php
Normal file
48
sample/payment-experience/PartiallyUpdateWebProfile.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
// #### Partially Update Web Profile
|
||||
// Use this call to partially update a web experience profile.
|
||||
// Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#partially-update-a-web-experience-profile
|
||||
|
||||
// We will be re-using the sample code to get a web profile. GetWebProfile.php will
|
||||
// create a new web profileId for sample, and return the web profile object.
|
||||
/** @var \PayPal\Api\WebProfile $webProfile */
|
||||
$webProfile = require 'GetWebProfile.php';
|
||||
|
||||
// ### Create Patch Operation
|
||||
// APIs allows us to pass an array of patches
|
||||
// to make patch operations.
|
||||
// Each Patch operation can be created by using Patch Class
|
||||
// as shown below
|
||||
$patchOperation1 = new \PayPal\Api\Patch();
|
||||
// The operation to perform. Required. Allowed values: add, remove, replace, move, copy, test
|
||||
$patchOperation1->setOp("add")
|
||||
// string containing a JSON-Pointer value that references a location within the target document (the target location) where the operation is performed. Required.
|
||||
->setPath("/presentation/brand_name")
|
||||
// New value to apply based on the operation.
|
||||
->setValue("New Brand Name");
|
||||
|
||||
// Similar patch operation to remove the landing page type
|
||||
$patchOperation2 = new \PayPal\Api\Patch();
|
||||
$patchOperation2->setOp("remove")
|
||||
->setPath("/flow_config/landing_page_type");
|
||||
|
||||
|
||||
//Generate an array of patch operations
|
||||
$patches = array($patchOperation1, $patchOperation2);
|
||||
|
||||
try {
|
||||
// Execute the partial update, to carry out these two operations on a given web profile object
|
||||
if ($webProfile->partial_update($patches, $apiContext)) {
|
||||
$webProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile);
|
||||
32
sample/payment-experience/UpdateWebProfile.php
Normal file
32
sample/payment-experience/UpdateWebProfile.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
// #### Update Web Profile
|
||||
// Use this call to update an experience profile.
|
||||
// Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#update-a-web-experience-profile
|
||||
|
||||
// We will be re-using the sample code to get a web profile. GetWebProfile.php will
|
||||
// create a new web profileId for sample, and return the web profile object.
|
||||
/** @var \PayPal\Api\WebProfile $webProfile */
|
||||
$webProfile = require 'GetWebProfile.php';
|
||||
|
||||
|
||||
// Updated the logo image of presentation object in a given web profile.
|
||||
$webProfile->getPresentation()->setLogoImage("http://www.google.com/favico.ico");
|
||||
|
||||
try {
|
||||
// Update the web profile to change the logo image.
|
||||
if ($webProfile->update($apiContext)) {
|
||||
// If the update is successfull, we can now get the object, and verify the web profile
|
||||
// object
|
||||
$updatedWebProfile = \PayPal\Api\WebProfile::get($webProfile->getId(), $apiContext);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
if (is_a($ex, '\PayPal\Exception\PPConnectionException')) {
|
||||
/** @var $ex \PayPal\Exception\PPConnectionException */
|
||||
var_dump($ex->getData());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_result("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $updatedWebProfile);
|
||||
Reference in New Issue
Block a user