/**
  * @param Config $config
  * @param \PayPal\Api\WebProfile $webProfile
  * @param string $experienceProfileId
  * @return bool
  */
 public static function UpdateExperienceProfile(Config $config, \PayPal\Api\WebProfile $webProfile, $experienceProfileId)
 {
     // set the id
     $webProfile->setId($experienceProfileId);
     // try to update
     try {
         $apiContext = self::getApiContext($config);
         $updated = $webProfile->update($apiContext);
     } catch (\Exception $ex) {
         return false;
     }
     if ($updated) {
         return true;
     } else {
         return false;
     }
 }
<?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 (\PayPal\Exception\PayPalConnectionException $ex) {
    ResultPrinter::printError("Get List of All Web Profiles", "Web Profiles", null, null, $ex);
    exit(1);
}
$result = '';
foreach ($list as $object) {
    $result .= $object->toJSON(128) . PHP_EOL;
}
ResultPrinter::printResult("Get List of All Web Profiles", "Web Profiles", null, null, $result);
return $list;
Ejemplo n.º 3
0
 /**
  * Lists all web experience profiles that exist for a merchant (or subject).
  *
  * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
  * @return WebProfile[]
  */
 public static function get_list($apiContext = null, $restCall = null)
 {
     $payLoad = "";
     $json = self::executeCall("/v1/payment-experience/web-profiles/", "GET", $payLoad, null, $apiContext, $restCall);
     return WebProfile::getList($json);
 }
Ejemplo n.º 4
0
<?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 (\PayPal\Exception\PayPalConnectionException $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Get Web Profile", "Web Profile", $webProfile->getId(), null, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Web Profile", "Web Profile", $webProfile->getId(), null, $webProfile);
return $webProfile;
 /**
  * @depends testGet
  * @param $createProfileResponse CreateProfileResponse
  */
 public function testDelete($createProfileResponse)
 {
     $webProfile = new WebProfile();
     $webProfile->setId($createProfileResponse->getId());
     $result = $webProfile->delete(null, $this->mockPayPalRestCall);
     $this->assertTrue($result);
 }
// #### 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")->setPath("/presentation/brand_name")->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) {
    ResultPrinter::printError("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $ex);
    exit(1);
}
ResultPrinter::printResult("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $webProfile);
Ejemplo n.º 7
0
 /**
  * @dataProvider mockProvider
  * @param WebProfile $obj
  */
 public function testDelete($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(true));
     $result = $obj->delete($mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }
Ejemplo n.º 8
0
 function delete_profile($id)
 {
     // auth
     $apiContext = $this->apiContext();
     // set WebProfile
     $webProfile = new WebProfile();
     $webProfile->setId($id);
     try {
         $webProfile->delete($apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($id == $this->get_config('PAYPAL_STANDARD_PROFILE')) {
         $this->delete_config('PAYPAL_STANDARD_PROFILE');
     }
     $this->delete_config($id, 'config_value');
 }
Ejemplo n.º 9
0
 public static function getPaymentExperienceProfileId()
 {
     $apiContext = self::getApiContext();
     $list = \PayPal\Api\WebProfile::get_list($apiContext);
     if (count($list) > 0) {
         return $list[0]->getId();
     }
     // ### 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("Login");
     // The URL on the merchant site for transferring to after a bank transfer payment.
     // $flowConfig->setBankTxnPendingUrl("http://www.yeowza.com/");
     // When set to "commit", the buyer is shown an amount, and the button text will read "Pay Now" on the checkout page.
     $flowConfig->setUserAction(null);
     // Defines the HTTP method to use to redirect the user to a return URL. A valid value is `GET` or `POST`.
     // $flowConfig->setReturnUriHttpMethod("GET");
     //
     // Parameters for style and presentation.
     $presentation = new \PayPal\Api\Presentation();
     // A URL to logo image. Allowed vaues: .gif, .jpg, or .png.
     $presentation->setLogoImage("http://betterliving.social/assets/images/paypal_checkout_brand.jpg")->setBrandName(\Tbmt\Config::get('brand.name'))->setLocaleCode("US");
     // A label to use as hypertext for the return to merchant link.
     // ->setReturnUrlLabel("Return")
     // A label to use as the title for the note to seller field. Used only when `allow_note` is `1`.
     // ->setNoteToSellerLabel("Thanks!");
     // 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(false)->setNoShipping(1)->setAddressOverride(0);
     // #### Payment Web experience profile resource
     $webProfile = new \PayPal\Api\WebProfile();
     // Name of the web experience profile. Required. Must be unique
     $webProfile->setName("happiness-guide")->setFlowConfig($flowConfig)->setPresentation($presentation)->setInputFields($inputFields)->setTemporary(false);
     $createProfileResponse = $webProfile->create($apiContext);
     return $createProfileResponse->getId();
 }
Ejemplo n.º 10
0
 public function storeCustomRecord($parameters)
 {
     // ### 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($this->request->input('landingPageType'));
     // The URL on the merchant site for transferring to after a bank transfer payment.
     $flowConfig->setBankTxnPendingUrl($this->request->input('bankTxnPendingUrl'));
     // Parameters for style and presentation.
     $presentation = new \PayPal\Api\Presentation();
     // A URL to logo image. Allowed vaues: .gif, .jpg, or .png.
     $presentation->setLogoImage($this->request->input('logoImage'))->setBrandName($this->request->input('brandName'))->setLocaleCode($this->request->input('localCode'));
     // 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($this->request->has('allowNote'))->setNoShipping((int) $this->request->input('shippingDataType'))->setAddressOverride((int) $this->request->input('displayShippingDataType'));
     // #### Payment Web experience profile resource
     $webProfile = new \PayPal\Api\WebProfile();
     // Name of the web experience profile. Required. Must be unique
     $webProfile->setName($this->request->input('name'))->setFlowConfig($flowConfig)->setPresentation($presentation)->setInputFields($inputFields);
     try {
         // Use this call to create a profile.
         $webProfile->create($this->apiContext);
     } catch (\PayPal\Exception\PayPalConnectionException $e) {
         dd($e);
     }
 }
Ejemplo n.º 11
0
 public function deleteCustomRecord($parameters)
 {
     $webProfile = new WebProfile();
     $webProfile->setId($parameters['id']);
     try {
         $webProfile->delete($this->apiContext);
     } catch (PayPalConnectionException $e) {
         dd($e);
     }
 }
Ejemplo n.º 12
0
 /**
  * Check if PayPal credentails are valid for given configuration.
  *
  * Uses WebProfile::get_list()
  *
  * @return bool
  */
 public function testCredentials($website)
 {
     try {
         $this->setApiContext($website);
         $response = WebProfile::get_list($this->_apiContext);
         return true;
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('iways_paypalplus')->__('Provided credentials not valid.'));
         return false;
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
 }