diff --git a/lib/PayPal/Api/CreateProfileResponse.php b/lib/PayPal/Api/CreateProfileResponse.php new file mode 100644 index 00000000..bdcae3fc --- /dev/null +++ b/lib/PayPal/Api/CreateProfileResponse.php @@ -0,0 +1,43 @@ +id = $id; + return $this; + } + + /** + * ID of the payment web experience profile. + * + * @return string + */ + public function getId() + { + return $this->id; + } + +} diff --git a/lib/PayPal/Api/FlowConfig.php b/lib/PayPal/Api/FlowConfig.php index 7fba2d89..3b046aa0 100644 --- a/lib/PayPal/Api/FlowConfig.php +++ b/lib/PayPal/Api/FlowConfig.php @@ -1,52 +1,120 @@ landing_page_type; - } - - /* - * @param string landing_page_type * - */ - - public function setLandingPageType($landing_page_type){ - $this->landing_page_type = $landing_page_type; - return $this; - } - - - /** - * - * @return string bank_txn_pending_url - */ - public function getBankTxnPendingUrl() { - return $this->bank_txn_pending_url; - } - - /* - * @param string bank_txn_pending_url * - */ - - public function setBankTxnPendingUrl($bank_txn_pending_url){ - $this->bank_txn_pending_url = $bank_txn_pending_url; - return $this; - } +class FlowConfig extends PPModel +{ + /** + * 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. + * + * + * @param string $landing_page_type + * + * @return $this + */ + public function setLandingPageType($landing_page_type) + { + $this->landing_page_type = $landing_page_type; + return $this; + } + + /** + * 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. + * + * @return string + */ + public function getLandingPageType() + { + return $this->landing_page_type; + } + + /** + * 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. + * + * @deprecated Instead use setLandingPageType + * + * @param string $landing_page_type + * @return $this + */ + public function setLanding_page_type($landing_page_type) + { + $this->landing_page_type = $landing_page_type; + return $this; + } + + /** + * 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. + * @deprecated Instead use getLandingPageType + * + * @return string + */ + public function getLanding_page_type() + { + return $this->landing_page_type; + } + + /** + * The URL on the merchant site for transferring to after a bank transfer payment. + * + * + * @param string $bank_txn_pending_url + * @throws InvalidArgumentException + * @return $this + */ + public function setBankTxnPendingUrl($bank_txn_pending_url) + { + UrlValidator::validate($bank_txn_pending_url, "BankTxnPendingUrl"); + $this->bank_txn_pending_url = $bank_txn_pending_url; + return $this; + } + + /** + * The URL on the merchant site for transferring to after a bank transfer payment. + * + * @return string + */ + public function getBankTxnPendingUrl() + { + return $this->bank_txn_pending_url; + } + + /** + * The URL on the merchant site for transferring to after a bank transfer payment. + * + * @deprecated Instead use setBankTxnPendingUrl + * + * @param string $bank_txn_pending_url + * @return $this + */ + public function setBank_txn_pending_url($bank_txn_pending_url) + { + $this->bank_txn_pending_url = $bank_txn_pending_url; + return $this; + } + /** + * The URL on the merchant site for transferring to after a bank transfer payment. + * @deprecated Instead use getBankTxnPendingUrl + * + * @return string + */ + public function getBank_txn_pending_url() + { + return $this->bank_txn_pending_url; + } } diff --git a/lib/PayPal/Api/InputFields.php b/lib/PayPal/Api/InputFields.php index 85d8c38d..08ecfeb3 100644 --- a/lib/PayPal/Api/InputFields.php +++ b/lib/PayPal/Api/InputFields.php @@ -1,4 +1,5 @@ no_shipping; - } - - /* - * @param integer no_shipping * - */ - - public function setNoShipping($no_shipping){ - $this->no_shipping = $no_shipping; - return $this; - } - - - /** - * - * @return integer address_override - */ - public function getAddressOverride() { - return $this->address_override; - } - - /* - * @param integer address_override * - */ - - public function setAddressOverride($address_override){ - $this->address_override = $address_override; - return $this; - } +class InputFields extends PPModel +{ + /** + * Enables the buyer to enter a note to the merchant on the PayPal page during checkout. + * + * + * @param bool $allow_note + * + * @return $this + */ + public function setAllowNote($allow_note) + { + $this->allow_note = $allow_note; + return $this; + } + + /** + * Enables the buyer to enter a note to the merchant on the PayPal page during checkout. + * + * @return bool + */ + public function getAllowNote() + { + return $this->allow_note; + } + + /** + * Enables the buyer to enter a note to the merchant on the PayPal page during checkout. + * + * @deprecated Instead use setAllowNote + * + * @param bool $allow_note + * @return $this + */ + public function setAllow_note($allow_note) + { + $this->allow_note = $allow_note; + return $this; + } + + /** + * Enables the buyer to enter a note to the merchant on the PayPal page during checkout. + * @deprecated Instead use getAllowNote + * + * @return bool + */ + public function getAllow_note() + { + return $this->allow_note; + } + + /** + * 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`. + * + * + * @param int $no_shipping + * + * @return $this + */ + public function setNoShipping($no_shipping) + { + $this->no_shipping = $no_shipping; + return $this; + } + + /** + * 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`. + * + * @return int + */ + public function getNoShipping() + { + return $this->no_shipping; + } + + /** + * 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`. + * + * @deprecated Instead use setNoShipping + * + * @param int $no_shipping + * @return $this + */ + public function setNo_shipping($no_shipping) + { + $this->no_shipping = $no_shipping; + return $this; + } + + /** + * 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`. + * @deprecated Instead use getNoShipping + * + * @return int + */ + public function getNo_shipping() + { + return $this->no_shipping; + } + + /** + * 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. + * + * + * @param int $address_override + * + * @return $this + */ + public function setAddressOverride($address_override) + { + $this->address_override = $address_override; + return $this; + } + + /** + * 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. + * + * @return int + */ + public function getAddressOverride() + { + return $this->address_override; + } + + /** + * 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. + * + * @deprecated Instead use setAddressOverride + * + * @param int $address_override + * @return $this + */ + public function setAddress_override($address_override) + { + $this->address_override = $address_override; + return $this; + } + + /** + * 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. + * @deprecated Instead use getAddressOverride + * + * @return int + */ + public function getAddress_override() + { + return $this->address_override; + } - /** - * - * @return boolean allow_note - */ - public function getAllowNote() { - return $this->allow_note; - } - - /* - * @param boolean allow_note * - */ - - public function setAllowNote($allow_note){ - $this->allow_note = $allow_note; - return $this; - } } diff --git a/lib/PayPal/Api/Patch.php b/lib/PayPal/Api/Patch.php new file mode 100644 index 00000000..d8fe6ae8 --- /dev/null +++ b/lib/PayPal/Api/Patch.php @@ -0,0 +1,118 @@ +op = $op; + return $this; + } + + /** + * The operation to perform. + * + * @return string + */ + public function getOp() + { + return $this->op; + } + + /** + * String containing a JSON-Pointer value that references a location within the target document where the operation is performed. + * + * + * @param string $path + * + * @return $this + */ + public function setPath($path) + { + $this->path = $path; + return $this; + } + + /** + * String containing a JSON-Pointer value that references a location within the target document where the operation is performed. + * + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * New value to apply based on the operation. op=remove does not require value. + * + * + * @param \PayPal\Api\object $value + * + * @return $this + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + /** + * New value to apply based on the operation. op=remove does not require value. + * + * @return \PayPal\Api\object + */ + public function getValue() + { + return $this->value; + } + + /** + * A string containing a JSON Pointer value that references the location in the target document from which to move the value. Required for use where op=move. + * + * + * @param string $from + * + * @return $this + */ + public function setFrom($from) + { + $this->from = $from; + return $this; + } + + /** + * A string containing a JSON Pointer value that references the location in the target document from which to move the value. Required for use where op=move. + * + * @return string + */ + public function getFrom() + { + return $this->from; + } + +} diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index ae534712..0213fc0a 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -374,7 +374,6 @@ public function getLinks() public function setExperienceProfileId($experience_profile_id) { $this->experience_profile_id = $experience_profile_id; - return $this; } diff --git a/lib/PayPal/Api/Presentation.php b/lib/PayPal/Api/Presentation.php index 534a0c4f..97ee0b05 100644 --- a/lib/PayPal/Api/Presentation.php +++ b/lib/PayPal/Api/Presentation.php @@ -1,4 +1,5 @@ brand_name; - } - - /* - * @param string brand_name * - */ - - public function setBrandName($brand_name){ - $this->brand_name = $brand_name; - return $this; - } - - - /** - * - * @return string logo_image - */ - public function getLogoImage() { - return $this->logo_image; - } - - /* - * @param string logo_image * - */ - - public function setLogoImage($logo_image){ - $this->logo_image = $logo_image; - return $this; - } +class Presentation extends PPModel +{ + /** + * A label that overrides the business name in the PayPal account on the PayPal pages. + * + * + * @param string $brand_name + * + * @return $this + */ + public function setBrandName($brand_name) + { + $this->brand_name = $brand_name; + return $this; + } + + /** + * A label that overrides the business name in the PayPal account on the PayPal pages. + * + * @return string + */ + public function getBrandName() + { + return $this->brand_name; + } + + /** + * A label that overrides the business name in the PayPal account on the PayPal pages. + * + * @deprecated Instead use setBrandName + * + * @param string $brand_name + * @return $this + */ + public function setBrand_name($brand_name) + { + $this->brand_name = $brand_name; + return $this; + } + + /** + * A label that overrides the business name in the PayPal account on the PayPal pages. + * @deprecated Instead use getBrandName + * + * @return string + */ + public function getBrand_name() + { + return $this->brand_name; + } + + /** + * A URL to logo image. Allowed vaues: `.gif`, `.jpg`, or `.png`. + * + * + * @param string $logo_image + * + * @return $this + */ + public function setLogoImage($logo_image) + { + $this->logo_image = $logo_image; + return $this; + } + + /** + * A URL to logo image. Allowed vaues: `.gif`, `.jpg`, or `.png`. + * + * @return string + */ + public function getLogoImage() + { + return $this->logo_image; + } + + /** + * A URL to logo image. Allowed vaues: `.gif`, `.jpg`, or `.png`. + * + * @deprecated Instead use setLogoImage + * + * @param string $logo_image + * @return $this + */ + public function setLogo_image($logo_image) + { + $this->logo_image = $logo_image; + return $this; + } + + /** + * A URL to logo image. Allowed vaues: `.gif`, `.jpg`, or `.png`. + * @deprecated Instead use getLogoImage + * + * @return string + */ + public function getLogo_image() + { + return $this->logo_image; + } + + /** + * Locale of pages displayed by PayPal payment experience. + * + * + * @param string $locale_code + * + * @return $this + */ + public function setLocaleCode($locale_code) + { + $this->locale_code = $locale_code; + return $this; + } + + /** + * Locale of pages displayed by PayPal payment experience. + * + * @return string + */ + public function getLocaleCode() + { + return $this->locale_code; + } + + /** + * Locale of pages displayed by PayPal payment experience. + * + * @deprecated Instead use setLocaleCode + * + * @param string $locale_code + * @return $this + */ + public function setLocale_code($locale_code) + { + $this->locale_code = $locale_code; + return $this; + } + + /** + * Locale of pages displayed by PayPal payment experience. + * @deprecated Instead use getLocaleCode + * + * @return string + */ + public function getLocale_code() + { + return $this->locale_code; + } - /** - * - * @return string locale_code - */ - public function getLocaleCode() { - return $this->logo_image; - } - - /* - * @param string locale_code * - */ - - public function setLocaleCode($locale_code){ - $this->locale_code = $locale_code; - return $this; - } } diff --git a/lib/PayPal/Api/WebProfile.php b/lib/PayPal/Api/WebProfile.php index b32467d7..ce924ab6 100644 --- a/lib/PayPal/Api/WebProfile.php +++ b/lib/PayPal/Api/WebProfile.php @@ -5,46 +5,58 @@ use PayPal\Common\PPModel; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; +use PayPal\Api\CreateProfileResponse; use PayPal\Transport\PPRestCall; - +use PayPal\Validation\ArgumentValidator; /** * Class WebProfile * - * @property string id - * @property string name - * @property InputFields input_fields - * @property FlowConfig flow_config - * @property Presentation presentation + * Payment Web experience profile resource + * + * @package PayPal\Api + * + * @property string id + * @property string name + * @property \PayPal\Api\FlowConfig flow_config + * @property \PayPal\Api\InputFields input_fields + * @property \PayPal\Api\Presentation presentation */ class WebProfile extends PPModel implements IResource { /** - * @var + * OAuth Credentials to use for this call + * + * @var \PayPal\Auth\OAuthTokenCredential $credential */ - private static $credential; + protected static $credential; - function __construct() { - $this->input_fields = new InputFields(); + /** + * Sets Credential + * + * @deprecated Pass ApiContext to create/get methods instead + * @param \PayPal\Auth\OAuthTokenCredential $credential + */ + public static function setCredential($credential) + { + self::$credential = $credential; } - //private $input_fields = array(); + /** - * Set ID * ID of the web experience profile. + * * * @param string $id - * + * * @return $this */ public function setId($id) { $this->id = $id; - return $this; } /** - * Get ID * ID of the web experience profile. * * @return string @@ -55,22 +67,20 @@ public function getId() } /** - * Set ID * Name of the web experience profile. + * * * @param string $name - * + * * @return $this */ public function setName($name) { $this->name = $name; - return $this; } /** - * Get name * Name of the web experience profile. * * @return string @@ -80,144 +90,243 @@ public function getName() return $this->name; } + /** + * Parameters for flow configuration. + * + * + * @param \PayPal\Api\FlowConfig $flow_config + * + * @return $this + */ + public function setFlowConfig($flow_config) + { + $this->flow_config = $flow_config; + return $this; + } + + /** + * Parameters for flow configuration. + * + * @return \PayPal\Api\FlowConfig + */ + public function getFlowConfig() + { + return $this->flow_config; + } + /** + * Parameters for flow configuration. + * + * @deprecated Instead use setFlowConfig + * + * @param \PayPal\Api\FlowConfig $flow_config + * @return $this + */ + public function setFlow_config($flow_config) + { + $this->flow_config = $flow_config; + return $this; + } + /** + * Parameters for flow configuration. + * @deprecated Instead use getFlowConfig + * + * @return \PayPal\Api\FlowConfig + */ + public function getFlow_config() + { + return $this->flow_config; + } /** + * Parameters for input fields customization. + * * - * @param InputFields $input_fields + * @param \PayPal\Api\InputFields $input_fields + * + * @return $this */ - public function setInputFields($input_fields) { + public function setInputFields($input_fields) + { $this->input_fields = $input_fields; return $this; } /** + * Parameters for input fields customization. * - * @return InputFields + * @return \PayPal\Api\InputFields */ - public function getInputFields() { + public function getInputFields() + { return $this->input_fields; } - /** + * Parameters for input fields customization. + * + * @deprecated Instead use setInputFields * - * @param FlowConfig $flow_config + * @param \PayPal\Api\InputFields $input_fields + * @return $this */ - public function setFlowConfig($flow_config) { - $this->flow_config = $flow_config; + public function setInput_fields($input_fields) + { + $this->input_fields = $input_fields; return $this; } /** + * Parameters for input fields customization. + * @deprecated Instead use getInputFields * - * @return FlowConfig + * @return \PayPal\Api\InputFields */ - public function getFlowConfig() { - return $this->flow_config; + public function getInput_fields() + { + return $this->input_fields; } - /** + * Parameters for style and presentation. + * * - * @param Presentation $presentation + * @param \PayPal\Api\Presentation $presentation + * + * @return $this */ - public function setPresentation($presentation) { + public function setPresentation($presentation) + { $this->presentation = $presentation; return $this; } /** + * Parameters for style and presentation. * - * @return Presentation + * @return \PayPal\Api\Presentation */ - public function getPresentation() { + public function getPresentation() + { return $this->presentation; } - /** - * Create - * - * @param \PayPal\Rest\ApiContext|null $apiContext + * Create a web experience profile by passing the name of the profile and other profile details in the request JSON to the request URI. * - * @return $this + * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @return CreateProfileResponse */ public function create($apiContext = null) { - $payLoad = $this->toJSON(); - if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles", "POST", $payLoad); - $this->fromJson($json); - - return $this; + $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/", "POST", $payLoad); + $ret = new CreateProfileResponse(); + $ret->fromJson($json); + return $ret; } + /** + * Update a web experience profile by passing the ID of the profile to the request URI. In addition, pass the profile details in the request JSON. If your request does not include values for all profile detail fields, the previously set values for the omitted fields are removed by this operation. + * + * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @return bool + */ public function update($apiContext = null) { + ArgumentValidator::validate($this->getId(), "Id"); $payLoad = $this->toJSON(); - if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new PPRestCall($apiContext); - - $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/".$this->getId(), "PUT", $payLoad); + $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/{$this->getId()}", "PUT", $payLoad); return true; } - /* - * Delete WebProfile resource for the given identifier. - * - * @param PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. - * @return void - */ - public function delete($apiContext = null) { - if ($this->getId() == null) { - throw new \InvalidArgumentException("Id cannot be null"); + /** + * Partially update an existing web experience profile by passing the ID of the profile to the request URI. In addition, pass a patch object in the request JSON that specifies the operation to perform, path of the profile location to update, and a new value if needed to complete the operation. + * + * @param Patch[] $patch + * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @return bool + */ + public function partial_update($patch, $apiContext = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($patch, 'patch'); + foreach ($patch as $patchObject) { + $payload[] = $patchObject->toArray(); } - $payLoad = ""; + + $payLoad = json_encode($payload); if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PPRestCall($apiContext); - $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/{$this->getId()}", "DELETE", $payLoad); + $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/{$this->getId()}", "PATCH", $payLoad); return true; } /** - * Get all webProfiles of a merchant. + * Retrieve the details of a particular web experience profile by passing the ID of the profile to the request URI. * - * @param \PayPal\Rest\ApiContext|null $apiContext - * - * @return WebProfiles + * @param string $profileId + * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @return WebProfile */ - public static function get_all($apiContext = null) + public static function get($profileId, $apiContext = null) { + ArgumentValidator::validate($profileId, 'profileId'); $payLoad = ""; - if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles", "GET", $payLoad); - $json = '{"web_profiles":'.$json.'}'; - - $ret = new WebProfiles(); + $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/$profileId", "GET", $payLoad); + $ret = new WebProfile(); $ret->fromJson($json); return $ret; - } + /** + * Lists all web experience profiles that exist for a merchant (or subject). + * + * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @return WebProfile[] + */ + public static function get_list($apiContext = null) + { + $payLoad = ""; + if ($apiContext == null) { + $apiContext = new ApiContext(self::$credential); + } + $call = new PPRestCall($apiContext); + $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/", "GET", $payLoad); + return WebProfile::getList($json); + } + /** + * Delete an existing web experience profile by passing the profile ID to the request URI. + * + * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @return bool + */ + public function delete($apiContext = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + $payLoad = ""; + if ($apiContext == null) { + $apiContext = new ApiContext(self::$credential); + } + $call = new PPRestCall($apiContext); + $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payment-experience/web-profiles/{$this->getId()}", "DELETE", $payLoad); + return true; + } } diff --git a/lib/PayPal/Api/WebProfiles.php b/lib/PayPal/Api/WebProfiles.php deleted file mode 100644 index 0523ab21..00000000 --- a/lib/PayPal/Api/WebProfiles.php +++ /dev/null @@ -1,37 +0,0 @@ -web_profiles = $web_profiles; - return $this; - } - - /** - * List of web profiles belonging to a merchant. - * - * @return \PayPal\Api\WebProfile - */ - public function getWebProfiles() { - return $this->web_profiles; - } - - - - - - -} diff --git a/lib/PayPal/Common/PPModel.php b/lib/PayPal/Common/PPModel.php index 7ad1ac30..5ac48d2c 100644 --- a/lib/PayPal/Common/PPModel.php +++ b/lib/PayPal/Common/PPModel.php @@ -1,6 +1,7 @@ isJson($data)) { - throw new \InvalidArgumentException("data should be either json or array representation of object"); - } + JsonValidator::validate($data); $this->fromJson($data); break; case "array": @@ -41,15 +40,28 @@ public function __construct($data = null) } /** - * Tests if the string provided is json representation or not. + * Returns a list of Object from Array or Json String. It is generally used when you json + * contains an array of this object * - * @param $string - * @return bool + * @param mixed $data Array object or json string representation + * @return array */ - private function isJson($string) + public static function getList($data) { - json_decode($string); - return (json_last_error() == JSON_ERROR_NONE); + if (!is_array($data) && JsonValidator::validate($data)) { + //Convert to Array if Json Data Sent + $data = json_decode($data, true); + } + if (!PPArrayUtil::isAssocArray($data)) { + $list = array(); + //This means, root element is array + foreach ($data as $k => $v) { + $obj = new static; + $obj->fromArray($v); + $list[] = $obj; + } + return $list; + } } /** @@ -139,16 +151,14 @@ private function _convertToArray($param) */ public function fromArray($arr) { - foreach ($arr as $k => $v) { if (is_array($v)) { $clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k); - if (PPArrayUtil::isAssocArray($v)) { /** @var self $o */ $o = new $clazz(); $o->fromArray($v); - $this->__set($k, $o); + $this->setValue($k, $o); } else { $arr = array(); foreach ($v as $nk => $nv) { @@ -160,15 +170,25 @@ public function fromArray($arr) $arr[$nk] = $nv; } } - $this->__set($k, $arr); + $this->setValue($k, $arr); } } else { - $this->$k = $v; + $this->$k = $v; } } return $this; } + private function setValue($key, $value) + { + if (ModelAccessorValidator::validate($this, $this->convertToCamelCase($key))) { + $setter = "set" . $this->convertToCamelCase($key); + $this->$setter($value); + } else { + $this->__set($key, $value); + } + } + /** * Fills object value from Json string * @@ -200,4 +220,4 @@ public function toJSON($options = 0) { return json_encode($this->toArray(), $options); } -} \ No newline at end of file +} diff --git a/lib/PayPal/Core/PPCredentialManager.php b/lib/PayPal/Core/PPCredentialManager.php index abb0c7e9..c636d935 100644 --- a/lib/PayPal/Core/PPCredentialManager.php +++ b/lib/PayPal/Core/PPCredentialManager.php @@ -151,7 +151,8 @@ public function getCredentialObject($userId = null) } if (empty($credObj)) { - throw new PPInvalidCredentialException("Invalid userId $userId"); + throw new PPInvalidCredentialException("Credential not found for " . ($userId ? $userId : " default user") . + ". Please make sure your configuration/APIContext has credential information"); } return $credObj; } diff --git a/lib/PayPal/Core/PPHttpConnection.php b/lib/PayPal/Core/PPHttpConnection.php index f3065a91..f5206424 100644 --- a/lib/PayPal/Core/PPHttpConnection.php +++ b/lib/PayPal/Core/PPHttpConnection.php @@ -88,7 +88,6 @@ public function execute($data) curl_setopt($ch, CURLOPT_URL, $this->httpConfig->getUrl()); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHttpHeaders()); - //Determine Curl Options based on Method switch ($this->httpConfig->getMethod()) { case 'POST': @@ -101,6 +100,7 @@ public function execute($data) //Default Option if Method not of given types in switch case if ($this->httpConfig->getMethod() != NULL) { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->httpConfig->getMethod()); + $this->logger->info("Method : " . $this->httpConfig->getMethod()); } //Logging Each Headers for debugging purposes @@ -142,10 +142,8 @@ public function execute($data) curl_close($ch); throw $ex; } - //Close the curl request curl_close($ch); - //More Exceptions based on HttpStatus Code if (in_array($httpStatus, self::$retryCodes)) { $ex = new PPConnectionException( @@ -158,7 +156,8 @@ public function execute($data) } else if ($httpStatus < 200 || $httpStatus >= 300) { $ex = new PPConnectionException( $this->httpConfig->getUrl(), - "Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}." + "Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}.", + $httpStatus ); $ex->setData($result); throw $ex; diff --git a/lib/PayPal/Validation/JsonValidator.php b/lib/PayPal/Validation/JsonValidator.php new file mode 100644 index 00000000..9bba9389 --- /dev/null +++ b/lib/PayPal/Validation/JsonValidator.php @@ -0,0 +1,28 @@ +setConfig( - array( - 'mode' => 'sandbox', - 'http.ConnectionTimeOut' => 30, - 'log.LogEnabled' => true, - 'log.FileName' => '../PayPal.log', - 'log.LogLevel' => 'FINE', - 'validation.level' => 'log' - ) - ); - - /* - // Register the sdk_config.ini file in current directory - // as the configuration source. - if(!defined("PP_CONFIG_PATH")) { - define("PP_CONFIG_PATH", __DIR__); - } - */ - - return $apiContext; -} +setConfig( + array( + 'mode' => 'sandbox', + 'http.ConnectionTimeOut' => 30, + 'log.LogEnabled' => true, + 'log.FileName' => '../PayPal.log', + 'log.LogLevel' => 'FINE', + 'validation.level' => 'log' + ) + ); + + /* + // Register the sdk_config.ini file in current directory + // as the configuration source. + if(!defined("PP_CONFIG_PATH")) { + define("PP_CONFIG_PATH", __DIR__); + } + */ + + return $apiContext; +} diff --git a/sample/common.php b/sample/common.php index a75d79c4..4f009596 100644 --- a/sample/common.php +++ b/sample/common.php @@ -13,26 +13,48 @@ use PayPal\Api\FundingInstrument; +function print_result($title, $objectName, $objectId = null, $output = null) +{ + echo "
" . $output->toJSON(JSON_PRETTY_PRINT) . ""; + } elseif (is_string($output)) { + echo "
$output"; + } + } + echo "
Cancel Invoice Sample
+Cancel Invoice Sample
This sample code demonstrate how you can cancel an invoice.
Create Invoice Sample
+Create Invoice Sample
This sample code demonstrate how you can create an invoice.
Get Invoice Sample
+Get Invoice Sample
This sample code demonstrate how you can retrieve an invoice.
List Invoices Sample
+List Invoices Sample
This sample code demonstrate how you can get all invoice from history.
Remind Invoice Sample
+Remind Invoice Sample
This sample code demonstrate how you can remind an invoice to the payer
Create Invoice Sample
+Create Invoice Sample
This sample code demonstrate how you can send a legitimate invoice to the payer
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
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.
The URL on the merchant site for transferring to after a bank transfer payment.
Parameters for style and presentation.
A URL to logo image. Allowed vaues: .gif, .jpg, or .png.
A label that overrides the business name in the PayPal account on the PayPal pages.
Locale of pages displayed by PayPal payment experience.
Parameters for input fields customization.
Enables the buyer to enter a note to the merchant on the PayPal page during checkout.
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.
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.
Payment Web experience profile resource
Name of the web experience profile. Required. Must be unique
Parameters for flow configuration.
Parameters for style and presentation.
Use this call to create a profile.
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.
Create a new instance of web Profile ID, and set the ID.
Execute the delete method
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.
If your request is successful, the API returns a web_profile object response that contains the profile details.
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 onApiContext
)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.
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
The operation to perform. Required. Allowed values: add, remove, replace, move, copy, test
string containing a JSON-Pointer value that references a location within the target document (the target location) where the operation is performed. Required.
New value to apply based on the operation.
Similar patch operation to remove the landing page type
Execute the partial update, to carry out these two operations on a given web profile object
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.
Updated the logo image of presentation object in a given web profile.
Update the web profile to change the logo image.
If the update is successfull, we can now get the object, and verify the web profile +object
AuthorizationCapture
+AuthorizationCapture
This sample code demonstrates how you can capture a previously authorized payment. API used: /v1/payments/payment
Create Payment using PayPal as payment method
+Create Payment using PayPal as payment method
This sample code demonstrates how you can process a PayPal Account based Payment. API used: /v1/payments/payment
CreatePaymentSample
+CreatePaymentSample
This sample code demonstrate how you can process a direct credit card payment. Please note that direct credit card payment and related features using the diff --git a/sample/doc/payments/CreatePaymentUsingPayPal.html b/sample/doc/payments/CreatePaymentUsingPayPal.html index e0455093..5bc27179 100644 --- a/sample/doc/payments/CreatePaymentUsingPayPal.html +++ b/sample/doc/payments/CreatePaymentUsingPayPal.html @@ -1,4 +1,4 @@ -
Create Payment using PayPal as payment method
+Create Payment using PayPal as payment method
This sample code demonstrates how you can process a PayPal Account based Payment. API used: /v1/payments/payment
Create payment using a saved credit card
+Create payment using a saved credit card
This sample code demonstrates how you can process a Payment using a previously stored credit card token. API used: /v1/payments/payment
Execute Payment Sample
+Execute Payment Sample
This sample shows how you can complete a payment that has been approved by the buyer by logging into paypal site. diff --git a/sample/doc/payments/GetAuthorization.html b/sample/doc/payments/GetAuthorization.html index 3a0d3d52..9d5a2879 100644 --- a/sample/doc/payments/GetAuthorization.html +++ b/sample/doc/payments/GetAuthorization.html @@ -1,4 +1,4 @@ -
GetAuthorization
+GetAuthorization
This sample code demonstrates how you can get details of an authorized payment. API used: /v1/payments/authorization/<$authorizationId>
GetCapture
+GetCapture
This sample code demonstrates how you can lookup the details of a captured payment. API used: /v1/payments/capture/<$captureId>
GetPaymentSample
+GetPaymentSample
This sample code demonstrate how you can retrieve a list of all Payment resources you've created using the Payments API. diff --git a/sample/doc/payments/ListPayments.html b/sample/doc/payments/ListPayments.html index 334446b6..3caf078d 100644 --- a/sample/doc/payments/ListPayments.html +++ b/sample/doc/payments/ListPayments.html @@ -1,4 +1,4 @@ -
GetPaymentList
+GetPaymentList
This sample code demonstrate how you can retrieve a list of all Payment resources you've created using the Payments API. diff --git a/sample/doc/payments/Reauthorization.html b/sample/doc/payments/Reauthorization.html index d0efa9cd..72004dca 100644 --- a/sample/doc/payments/Reauthorization.html +++ b/sample/doc/payments/Reauthorization.html @@ -1,4 +1,4 @@ -
Reauthorization Sample
+Reauthorization Sample
This sample code demonstrates how you can reauthorize a PayPal account payment. API used: v1/payments/authorization/{authorization_id}/reauthorize
Refund Capture Sample
+Refund Capture Sample
This sample code demonstrates how you can process a refund on a Captured transaction. API used: /v1/payments/capture/{}/refund
VoidAuthorization
+VoidAuthorization
This sample code demonstrates how you can void an authorized payment. API used: /v1/payments/authorization/<{authorizationid}>/void"
Get Sale sample
+Get Sale sample
Sale transactions are nothing but completed payments. This sample code demonstrates how you can retrieve details of completed Sale Transaction. diff --git a/sample/doc/sale/RefundSale.html b/sample/doc/sale/RefundSale.html index f1f36139..9adfae03 100644 --- a/sample/doc/sale/RefundSale.html +++ b/sample/doc/sale/RefundSale.html @@ -1,4 +1,4 @@ -
Sale Refund Sample
+Sale Refund Sample
This sample code demonstrate how you can process a refund on a sale transaction created using the Payments API. diff --git a/sample/doc/vault/CreateCreditCard.html b/sample/doc/vault/CreateCreditCard.html index 96253804..8220c4f7 100644 --- a/sample/doc/vault/CreateCreditCard.html +++ b/sample/doc/vault/CreateCreditCard.html @@ -1,4 +1,4 @@ -
Create Credit Card Sample
+Create Credit Card Sample
You can store credit card details securely with PayPal. You can then use the returned Credit card id to process future payments. diff --git a/sample/doc/vault/DeleteCreditCard.html b/sample/doc/vault/DeleteCreditCard.html index ed58f8a0..d5f0578b 100644 --- a/sample/doc/vault/DeleteCreditCard.html +++ b/sample/doc/vault/DeleteCreditCard.html @@ -1,4 +1,4 @@ -
Delete CreditCard Sample
+Delete CreditCard Sample
This sample code demonstrate how you can delete a saved credit card. API used: /v1/vault/credit-card/{}
diff --git a/sample/doc/vault/GetCreditCard.html b/sample/doc/vault/GetCreditCard.html
index a596645e..2c0e6622 100644
--- a/sample/doc/vault/GetCreditCard.html
+++ b/sample/doc/vault/GetCreditCard.html
@@ -1,4 +1,4 @@
-vault/GetCreditCard sample/vault/GetCreditCard.php <?php vault/GetCreditCard vault/GetCreditCard.php <?php
+
+
+
+
+
+
Get Credit Card Sample
+Get Credit Card Sample
The CreditCard resource allows you to retrieve previously saved CreditCards. API called: '/v1/vault/credit-card' diff --git a/sample/index.html b/sample/index.html index b31067d0..f65bc136 100644 --- a/sample/index.html +++ b/sample/index.html @@ -235,6 +235,69 @@
Authorization and capture
Payment Experience
++-
+
+
+
+ Execute
+ Source
+
+
+
+ -
+
+
+
+ Execute
+ Source
+
+
+
+ -
+
+
+
+ Execute
+ Source
+
+
+
+ -
+
+
+
+ Execute
+ Source
+
+
+
+ -
+
+
+
+ Execute
+ Source
+
+
+
+ -
+
+
+
+ Execute
+ Source
+
+
+
+
+Create a web experience profile
Retrieve a web experience profile
List web experience profiles
Update a web experience profile
Partially update a web experience profile
Delete a web experience profile
Invoice
diff --git a/sample/payment-experience/CreateWebProfile.php b/sample/payment-experience/CreateWebProfile.php new file mode 100644 index 00000000..a0a47a93 --- /dev/null +++ b/sample/payment-experience/CreateWebProfile.php @@ -0,0 +1,60 @@ +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; diff --git a/sample/payment-experience/DeleteWebProfile.php b/sample/payment-experience/DeleteWebProfile.php new file mode 100644 index 00000000..dbc6849e --- /dev/null +++ b/sample/payment-experience/DeleteWebProfile.php @@ -0,0 +1,30 @@ +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()); diff --git a/sample/payment-experience/GetWebProfile.php b/sample/payment-experience/GetWebProfile.php new file mode 100644 index 00000000..27798585 --- /dev/null +++ b/sample/payment-experience/GetWebProfile.php @@ -0,0 +1,28 @@ +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; diff --git a/sample/payment-experience/ListWebProfiles.php b/sample/payment-experience/ListWebProfiles.php new file mode 100644 index 00000000..641fd1d4 --- /dev/null +++ b/sample/payment-experience/ListWebProfiles.php @@ -0,0 +1,28 @@ +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; diff --git a/sample/payment-experience/PartiallyUpdateWebProfile.php b/sample/payment-experience/PartiallyUpdateWebProfile.php new file mode 100644 index 00000000..fdfd9954 --- /dev/null +++ b/sample/payment-experience/PartiallyUpdateWebProfile.php @@ -0,0 +1,48 @@ +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); diff --git a/sample/payment-experience/UpdateWebProfile.php b/sample/payment-experience/UpdateWebProfile.php new file mode 100644 index 00000000..4733b118 --- /dev/null +++ b/sample/payment-experience/UpdateWebProfile.php @@ -0,0 +1,32 @@ +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); diff --git a/tests/PayPal/Test/Api/WebProfileTest.php b/tests/PayPal/Test/Api/WebProfileTest.php new file mode 100644 index 00000000..c88d64dc --- /dev/null +++ b/tests/PayPal/Test/Api/WebProfileTest.php @@ -0,0 +1,83 @@ +toJson(); + $this->assertEquals($requestBodyEncoded, $json); + } + + + /** + * @group integration + */ + public function testCreateprofileOperation() + { + $requestBody = '{"name":"someName2' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":1,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"http://www.ebay.com"}}'; + $requestBodyEncoded = json_encode(json_decode($requestBody, true)); + $object = new WebProfile($requestBodyEncoded); + $response = $object->create(null); + $this->assertNotNull($response); + return $response->getId(); + } + + + /** + * @depends testCreateprofileOperation + * @group integration + */ + public function testGetprofileOperation($profileId) + { + $response = WebProfile::get($profileId, null); + $this->assertNotNull($response); + $this->assertEquals($response->getId(), $profileId); + $this->assertEquals("http://www.ebay.com", $response->getPresentation()->getLogoImage()); + $this->assertEquals(1, $response->getInputFields()->getNoShipping()); + $this->assertEquals(1, $response->getInputFields()->getAddressOverride()); + $this->assertEquals("billing", $response->getFlowConfig()->getLandingPageType()); + $this->assertEquals("http://www.ebay.com", $response->getFlowConfig()->getBankTxnPendingUrl()); + return $response->getId(); + } + + + public function testValidationerrorSerialization() + { + $requestBody = '{"name":"sampleName' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":4,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"ht//www.ebay.com"}}'; + $requestBodyEncoded = json_encode(json_decode($requestBody, true)); + $object = new WebProfile($requestBodyEncoded); + + $json = $object->toJson(); + $this->assertEquals($requestBodyEncoded, $json); + } + + + /** + * @group integration + * @expectedException PayPal\Exception\PPConnectionException + * @expectedExceptionCode 400 + */ + public function testValidationerrorOperation() + { + $requestBody = '{"name":"sampleName' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":4,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"ht//www.ebay.com"}}'; + $requestBodyEncoded = json_encode(json_decode($requestBody, true)); + $object = new WebProfile($requestBodyEncoded); + $response = $object->create(null); + return $response->getId(); + } + +} diff --git a/tests/PayPal/Test/Common/ModelTest.php b/tests/PayPal/Test/Common/ModelTest.php index 3a5b33fd..ba924cb0 100644 --- a/tests/PayPal/Test/Common/ModelTest.php +++ b/tests/PayPal/Test/Common/ModelTest.php @@ -1,167 +1,167 @@ -setName("test"); - $o->setDescription("description"); - - $this->assertEquals("test", $o->getName()); - $this->assertEquals("description", $o->getDescription()); - - $json = $o->toJSON(); - $this->assertEquals('{"name":"test","description":"description"}', $json); - - $newO = new SimpleClass(); - $newO->fromJson($json); - $this->assertEquals($o, $newO); - - } - - public function testConstructorJSON() - { - $obj = new SimpleClass('{"name":"test","description":"description"}'); - $this->assertEquals($obj->getName(), "test"); - $this->assertEquals($obj->getDescription(), "description"); - } - - public function testConstructorArray() - { - $arr = array('name' => 'test', 'description' => 'description'); - $obj = new SimpleClass($arr); - $this->assertEquals($obj->getName(), "test"); - $this->assertEquals($obj->getDescription(), "description"); - } - - public function testConstructorNull() - { - $obj = new SimpleClass(null); - $this->assertNotEquals($obj->getName(), "test"); - $this->assertNotEquals($obj->getDescription(), "description"); - $this->assertNull($obj->getName()); - $this->assertNull($obj->getDescription()); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage data should be either json or array representation of object - */ - public function testConstructorInvalidInput() - { - new SimpleClass("Something that is not even correct"); - } - - public function testSimpleClassObjectConversion() - { - $json = '{"name":"test","description":"description"}'; - - $obj = new SimpleClass(); - $obj->fromJson($json); - - $this->assertEquals("test", $obj->getName()); - $this->assertEquals("description", $obj->getDescription()); - - } - - public function testSimpleClassObjectInvalidConversion() - { - try { - $json = '{"name":"test","description":"description","invalid":"value"}'; - - $obj = new SimpleClass(); - $obj->fromJson($json); - - $this->assertEquals("test", $obj->getName()); - $this->assertEquals("description", $obj->getDescription()); - } catch (\PHPUnit_Framework_Error_Notice $ex) { - echo $ex->getMessage(); - } - } - - /** - * @outputBuffering enabled - */ - public function testInvalidMagicMethod() - { - $obj = new SimpleClass(); - try { - $obj->invalid = "value2"; - $this->assertEquals($obj->invalid, "value2"); - if (PPConfigManager::getInstance()->get('validation.level') == 'strict') { - $this->fail("It should have thrown a Notice Error"); - } - } catch (\PHPUnit_Framework_Error_Notice $ex) { - - } - } - - /** - * @outputBuffering enabled - */ - public function testInvalidMagicMethodWithDisabledValidation() - { - PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'disabled')); - $obj = new SimpleClass(); - try { - $obj->invalid = "value2"; - $this->assertEquals($obj->invalid, "value2"); - } catch (\PHPUnit_Framework_Error_Notice $ex) { - $this->fail("It should not have thrown a Notice Error as it is disabled."); - } - PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict')); - } - - public function testInvalidMagicMethodWithValidationLevel() - { - PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'log')); - $obj = new SimpleClass(); - $obj->invalid2 = "value2"; - $this->assertEquals($obj->invalid2, "value2"); - PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict')); - } - - public function testArrayClassConversion() - { - $o = new ArrayClass(); - $o->setName("test"); - $o->setDescription("description"); - $o->setTags(array('payment', 'info', 'test')); - - $this->assertEquals("test", $o->getName()); - $this->assertEquals("description", $o->getDescription()); - $this->assertEquals(array('payment', 'info', 'test'), $o->getTags()); - - $json = $o->toJSON(); - $this->assertEquals('{"name":"test","description":"description","tags":["payment","info","test"]}', $json); - - $newO = new ArrayClass(); - $newO->fromJson($json); - $this->assertEquals($o, $newO); - } - - public function testNestedClassConversion() - { - $n = new ArrayClass(); - $n->setName("test"); - $n->setDescription("description"); - $o = new NestedClass(); - $o->setId('123'); - $o->setInfo($n); - - $this->assertEquals("123", $o->getId()); - $this->assertEquals("test", $o->getInfo()->getName()); - - $json = $o->toJSON(); - $this->assertEquals('{"id":"123","info":{"name":"test","description":"description"}}', $json); - - $newO = new NestedClass(); - $newO->fromJson($json); - $this->assertEquals($o, $newO); - } -} +setName("test"); + $o->setDescription("description"); + + $this->assertEquals("test", $o->getName()); + $this->assertEquals("description", $o->getDescription()); + + $json = $o->toJSON(); + $this->assertEquals('{"name":"test","description":"description"}', $json); + + $newO = new SimpleClass(); + $newO->fromJson($json); + $this->assertEquals($o, $newO); + + } + + public function testConstructorJSON() + { + $obj = new SimpleClass('{"name":"test","description":"description"}'); + $this->assertEquals($obj->getName(), "test"); + $this->assertEquals($obj->getDescription(), "description"); + } + + public function testConstructorArray() + { + $arr = array('name' => 'test', 'description' => 'description'); + $obj = new SimpleClass($arr); + $this->assertEquals($obj->getName(), "test"); + $this->assertEquals($obj->getDescription(), "description"); + } + + public function testConstructorNull() + { + $obj = new SimpleClass(null); + $this->assertNotEquals($obj->getName(), "test"); + $this->assertNotEquals($obj->getDescription(), "description"); + $this->assertNull($obj->getName()); + $this->assertNull($obj->getDescription()); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid JSON String + */ + public function testConstructorInvalidInput() + { + new SimpleClass("Something that is not even correct"); + } + + public function testSimpleClassObjectConversion() + { + $json = '{"name":"test","description":"description"}'; + + $obj = new SimpleClass(); + $obj->fromJson($json); + + $this->assertEquals("test", $obj->getName()); + $this->assertEquals("description", $obj->getDescription()); + + } + + public function testSimpleClassObjectInvalidConversion() + { + try { + $json = '{"name":"test","description":"description","invalid":"value"}'; + + $obj = new SimpleClass(); + $obj->fromJson($json); + + $this->assertEquals("test", $obj->getName()); + $this->assertEquals("description", $obj->getDescription()); + } catch (\PHPUnit_Framework_Error_Notice $ex) { + echo $ex->getMessage(); + } + } + + /** + * @outputBuffering enabled + */ + public function testInvalidMagicMethod() + { + $obj = new SimpleClass(); + try { + $obj->invalid = "value2"; + $this->assertEquals($obj->invalid, "value2"); + if (PPConfigManager::getInstance()->get('validation.level') == 'strict') { + $this->fail("It should have thrown a Notice Error"); + } + } catch (\PHPUnit_Framework_Error_Notice $ex) { + + } + } + + /** + * @outputBuffering enabled + */ + public function testInvalidMagicMethodWithDisabledValidation() + { + PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'disabled')); + $obj = new SimpleClass(); + try { + $obj->invalid = "value2"; + $this->assertEquals($obj->invalid, "value2"); + } catch (\PHPUnit_Framework_Error_Notice $ex) { + $this->fail("It should not have thrown a Notice Error as it is disabled."); + } + PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict')); + } + + public function testInvalidMagicMethodWithValidationLevel() + { + PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'log')); + $obj = new SimpleClass(); + $obj->invalid2 = "value2"; + $this->assertEquals($obj->invalid2, "value2"); + PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict')); + } + + public function testArrayClassConversion() + { + $o = new ArrayClass(); + $o->setName("test"); + $o->setDescription("description"); + $o->setTags(array('payment', 'info', 'test')); + + $this->assertEquals("test", $o->getName()); + $this->assertEquals("description", $o->getDescription()); + $this->assertEquals(array('payment', 'info', 'test'), $o->getTags()); + + $json = $o->toJSON(); + $this->assertEquals('{"name":"test","description":"description","tags":["payment","info","test"]}', $json); + + $newO = new ArrayClass(); + $newO->fromJson($json); + $this->assertEquals($o, $newO); + } + + public function testNestedClassConversion() + { + $n = new ArrayClass(); + $n->setName("test"); + $n->setDescription("description"); + $o = new NestedClass(); + $o->setId('123'); + $o->setInfo($n); + + $this->assertEquals("123", $o->getId()); + $this->assertEquals("test", $o->getInfo()->getName()); + + $json = $o->toJSON(); + $this->assertEquals('{"id":"123","info":{"name":"test","description":"description"}}', $json); + + $newO = new NestedClass(); + $newO->fromJson($json); + $this->assertEquals($o, $newO); + } +}