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 "

$title

"; + + if ($objectId) { + echo "
Created " . ($objectName ? $objectName : "Object") . " with ID: $objectId
"; + } + + if ($output) { + if (is_a($output, 'PayPal\Common\PPModel')) { + /** @var $output \PayPal\Common\PPModel */ + echo "
" . $output->toJSON(JSON_PRETTY_PRINT) . "
"; + } elseif (is_string($output)) { + echo "
$output
"; + } + } + echo "
"; + +} + /** * ### getBaseUrl function * // utility function that returns base url for * // determining return/cancel urls + * * @return string */ -function getBaseUrl() { - - $protocol = 'http'; - if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { - $protocol .= 's'; - $protocol_port = $_SERVER['SERVER_PORT']; - } else { - $protocol_port = 80; - } - - $host = $_SERVER['HTTP_HOST']; - $port = $_SERVER['SERVER_PORT']; - $request = $_SERVER['PHP_SELF']; - return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); +function getBaseUrl() +{ + + $protocol = 'http'; + if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { + $protocol .= 's'; + $protocol_port = $_SERVER['SERVER_PORT']; + } else { + $protocol_port = 80; + } + + $host = $_SERVER['HTTP_HOST']; + $port = $_SERVER['SERVER_PORT']; + $request = $_SERVER['PHP_SELF']; + return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); } /** @@ -41,51 +63,52 @@ function getBaseUrl() { * @param PayPal\Api\ApiContext apiContext * @return PayPal\Api\Authorization */ -function createAuthorization($apiContext) { - $addr = new Address(); - $addr->setLine1("3909 Witmer Road") - ->setLine2("Niagara Falls") - ->setCity("Niagara Falls") - ->setState("NY") - ->setPostalCode("14305") - ->setCountryCode("US") - ->setPhone("716-298-1822"); - - $card = new CreditCard(); - $card->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("Shopper") - ->setBillingAddress($addr); - - $fi = new FundingInstrument(); - $fi->setCreditCard($card); - - $payer = new Payer(); - $payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); - - $amount = new Amount(); - $amount->setCurrency("USD") - ->setTotal("1.00"); - - $transaction = new Transaction(); - $transaction->setAmount($amount) - ->setDescription("Payment description."); - - $payment = new Payment(); - - // Setting intent to authorize creates a payment - // authorization. Setting it to sale creates actual payment - $payment->setIntent("authorize") - ->setPayer($payer) - ->setTransactions(array($transaction)); - - $paymnt = $payment->create($apiContext); - $resArray = $paymnt->toArray(); - - return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +function createAuthorization($apiContext) +{ + $addr = new Address(); + $addr->setLine1("3909 Witmer Road") + ->setLine2("Niagara Falls") + ->setCity("Niagara Falls") + ->setState("NY") + ->setPostalCode("14305") + ->setCountryCode("US") + ->setPhone("716-298-1822"); + + $card = new CreditCard(); + $card->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper") + ->setBillingAddress($addr); + + $fi = new FundingInstrument(); + $fi->setCreditCard($card); + + $payer = new Payer(); + $payer->setPaymentMethod("credit_card") + ->setFundingInstruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD") + ->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount) + ->setDescription("Payment description."); + + $payment = new Payment(); + +// Setting intent to authorize creates a payment +// authorization. Setting it to sale creates actual payment + $payment->setIntent("authorize") + ->setPayer($payer) + ->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; } diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 364695fa..291e9f0a 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -25,7 +25,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/invoice/CancelInvoice.php", - "projectPath": "sample/invoice/CancelInvoice.php", + "projectPath": "invoice/CancelInvoice.php", "targetPath": "invoice/CancelInvoice", "pageTitle": "invoice/CancelInvoice", "title": "CancelInvoice" @@ -81,7 +81,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/invoice/CreateInvoice.php", - "projectPath": "sample/invoice/CreateInvoice.php", + "projectPath": "invoice/CreateInvoice.php", "targetPath": "invoice/CreateInvoice", "pageTitle": "invoice/CreateInvoice", "title": "CreateInvoice" @@ -169,7 +169,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/invoice/GetInvoice.php", - "projectPath": "sample/invoice/GetInvoice.php", + "projectPath": "invoice/GetInvoice.php", "targetPath": "invoice/GetInvoice", "pageTitle": "invoice/GetInvoice", "title": "GetInvoice" @@ -209,7 +209,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/invoice/ListInvoice.php", - "projectPath": "sample/invoice/ListInvoice.php", + "projectPath": "invoice/ListInvoice.php", "targetPath": "invoice/ListInvoice", "pageTitle": "invoice/ListInvoice", "title": "ListInvoice" @@ -249,7 +249,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/invoice/RemindInvoice.php", - "projectPath": "sample/invoice/RemindInvoice.php", + "projectPath": "invoice/RemindInvoice.php", "targetPath": "invoice/RemindInvoice", "pageTitle": "invoice/RemindInvoice", "title": "RemindInvoice" @@ -305,7 +305,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/invoice/SendInvoice.php", - "projectPath": "sample/invoice/SendInvoice.php", + "projectPath": "invoice/SendInvoice.php", "targetPath": "invoice/SendInvoice", "pageTitle": "invoice/SendInvoice", "title": "SendInvoice" @@ -343,6 +343,209 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 ] } ] + }, { + "type": "folder", + "data": { + "path": "payment-experience", + "title": "payment-experience" + }, + "depth": 1, + "children": [ + { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payment-experience/CreateWebProfile.php", + "projectPath": "payment-experience/CreateWebProfile.php", + "targetPath": "payment-experience/CreateWebProfile", + "pageTitle": "payment-experience/CreateWebProfile", + "title": "CreateWebProfile" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Web Profile", + "slug": "create-web-profile" + }, + "depth": 3, + "children": [ + { + "type": "heading", + "data": { + "level": 4, + "title": "Payment Web experience profile resource", + "slug": "payment-web-experience-profile-resource" + }, + "depth": 4 + } + ] + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payment-experience/DeleteWebProfile.php", + "projectPath": "payment-experience/DeleteWebProfile.php", + "targetPath": "payment-experience/DeleteWebProfile", + "pageTitle": "payment-experience/DeleteWebProfile", + "title": "DeleteWebProfile" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 4, + "title": "Delete Web Profile", + "slug": "delete-web-profile" + }, + "depth": 4 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payment-experience/GetWebProfile.php", + "projectPath": "payment-experience/GetWebProfile.php", + "targetPath": "payment-experience/GetWebProfile", + "pageTitle": "payment-experience/GetWebProfile", + "title": "GetWebProfile" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Get Web Profile", + "slug": "get-web-profile" + }, + "depth": 3 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payment-experience/ListWebProfiles.php", + "projectPath": "payment-experience/ListWebProfiles.php", + "targetPath": "payment-experience/ListWebProfiles", + "pageTitle": "payment-experience/ListWebProfiles", + "title": "ListWebProfiles" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Retrieve List of All Web Profiles", + "slug": "retrieve-list-of-all-web-profiles" + }, + "depth": 3 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payment-experience/PartiallyUpdateWebProfile.php", + "projectPath": "payment-experience/PartiallyUpdateWebProfile.php", + "targetPath": "payment-experience/PartiallyUpdateWebProfile", + "pageTitle": "payment-experience/PartiallyUpdateWebProfile", + "title": "PartiallyUpdateWebProfile" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 4, + "title": "Partially Update Web Profile", + "slug": "partially-update-web-profile" + }, + "depth": 4 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Patch Operation", + "slug": "create-patch-operation" + }, + "depth": 3 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payment-experience/UpdateWebProfile.php", + "projectPath": "payment-experience/UpdateWebProfile.php", + "targetPath": "payment-experience/UpdateWebProfile", + "pageTitle": "payment-experience/UpdateWebProfile", + "title": "UpdateWebProfile" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 4, + "title": "Update Web Profile", + "slug": "update-web-profile" + }, + "depth": 4 + } + ] + } + ] }, { "type": "folder", "data": { @@ -363,7 +566,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/AuthorizationCapture.php", - "projectPath": "sample/payments/AuthorizationCapture.php", + "projectPath": "payments/AuthorizationCapture.php", "targetPath": "payments/AuthorizationCapture", "pageTitle": "payments/AuthorizationCapture", "title": "AuthorizationCapture" @@ -403,7 +606,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/CreateFuturePayment.php", - "projectPath": "sample/payments/CreateFuturePayment.php", + "projectPath": "payments/CreateFuturePayment.php", "targetPath": "payments/CreateFuturePayment", "pageTitle": "payments/CreateFuturePayment", "title": "CreateFuturePayment" @@ -491,7 +694,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/CreatePayment.php", - "projectPath": "sample/payments/CreatePayment.php", + "projectPath": "payments/CreatePayment.php", "targetPath": "payments/CreatePayment", "pageTitle": "payments/CreatePayment", "title": "CreatePayment" @@ -595,7 +798,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/CreatePaymentUsingPayPal.php", - "projectPath": "sample/payments/CreatePaymentUsingPayPal.php", + "projectPath": "payments/CreatePaymentUsingPayPal.php", "targetPath": "payments/CreatePaymentUsingPayPal", "pageTitle": "payments/CreatePaymentUsingPayPal", "title": "CreatePaymentUsingPayPal" @@ -707,7 +910,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/CreatePaymentUsingSavedCard.php", - "projectPath": "sample/payments/CreatePaymentUsingSavedCard.php", + "projectPath": "payments/CreatePaymentUsingSavedCard.php", "targetPath": "payments/CreatePaymentUsingSavedCard", "pageTitle": "payments/CreatePaymentUsingSavedCard", "title": "CreatePaymentUsingSavedCard" @@ -811,7 +1014,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/ExecutePayment.php", - "projectPath": "sample/payments/ExecutePayment.php", + "projectPath": "payments/ExecutePayment.php", "targetPath": "payments/ExecutePayment", "pageTitle": "payments/ExecutePayment", "title": "ExecutePayment" @@ -840,7 +1043,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/GetAuthorization.php", - "projectPath": "sample/payments/GetAuthorization.php", + "projectPath": "payments/GetAuthorization.php", "targetPath": "payments/GetAuthorization", "pageTitle": "payments/GetAuthorization", "title": "GetAuthorization" @@ -880,7 +1083,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/GetCapture.php", - "projectPath": "sample/payments/GetCapture.php", + "projectPath": "payments/GetCapture.php", "targetPath": "payments/GetCapture", "pageTitle": "payments/GetCapture", "title": "GetCapture" @@ -928,7 +1131,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/GetPayment.php", - "projectPath": "sample/payments/GetPayment.php", + "projectPath": "payments/GetPayment.php", "targetPath": "payments/GetPayment", "pageTitle": "payments/GetPayment", "title": "GetPayment" @@ -968,7 +1171,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/ListPayments.php", - "projectPath": "sample/payments/ListPayments.php", + "projectPath": "payments/ListPayments.php", "targetPath": "payments/ListPayments", "pageTitle": "payments/ListPayments", "title": "ListPayments" @@ -1008,7 +1211,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/Reauthorization.php", - "projectPath": "sample/payments/Reauthorization.php", + "projectPath": "payments/Reauthorization.php", "targetPath": "payments/Reauthorization", "pageTitle": "payments/Reauthorization", "title": "Reauthorization" @@ -1064,7 +1267,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/RefundCapture.php", - "projectPath": "sample/payments/RefundCapture.php", + "projectPath": "payments/RefundCapture.php", "targetPath": "payments/RefundCapture", "pageTitle": "payments/RefundCapture", "title": "RefundCapture" @@ -1112,7 +1315,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/payments/VoidAuthorization.php", - "projectPath": "sample/payments/VoidAuthorization.php", + "projectPath": "payments/VoidAuthorization.php", "targetPath": "payments/VoidAuthorization", "pageTitle": "payments/VoidAuthorization", "title": "VoidAuthorization" @@ -1162,7 +1365,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/sale/GetSale.php", - "projectPath": "sample/sale/GetSale.php", + "projectPath": "sale/GetSale.php", "targetPath": "sale/GetSale", "pageTitle": "sale/GetSale", "title": "GetSale" @@ -1202,7 +1405,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/sale/RefundSale.php", - "projectPath": "sample/sale/RefundSale.php", + "projectPath": "sale/RefundSale.php", "targetPath": "sale/RefundSale", "pageTitle": "sale/RefundSale", "title": "RefundSale" @@ -1268,7 +1471,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/vault/CreateCreditCard.php", - "projectPath": "sample/vault/CreateCreditCard.php", + "projectPath": "vault/CreateCreditCard.php", "targetPath": "vault/CreateCreditCard", "pageTitle": "vault/CreateCreditCard", "title": "CreateCreditCard" @@ -1316,7 +1519,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/vault/DeleteCreditCard.php", - "projectPath": "sample/vault/DeleteCreditCard.php", + "projectPath": "vault/DeleteCreditCard.php", "targetPath": "vault/DeleteCreditCard", "pageTitle": "vault/DeleteCreditCard", "title": "DeleteCreditCard" @@ -1372,7 +1575,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "name": "PHP" }, "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/vault/GetCreditCard.php", - "projectPath": "sample/vault/GetCreditCard.php", + "projectPath": "vault/GetCreditCard.php", "targetPath": "vault/GetCreditCard", "pageTitle": "vault/GetCreditCard", "title": "GetCreditCard" diff --git a/sample/doc/invoice/CancelInvoice.html b/sample/doc/invoice/CancelInvoice.html index 29efce51..a6440013 100644 --- a/sample/doc/invoice/CancelInvoice.html +++ b/sample/doc/invoice/CancelInvoice.html @@ -1,4 +1,4 @@ -invoice/CancelInvoice
sample/invoice/CancelInvoice.php
<?php

Cancel Invoice Sample

+invoice/CancelInvoice
invoice/CancelInvoice.php
<?php

Cancel Invoice Sample

This sample code demonstrate how you can cancel an invoice.

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/invoice/CreateInvoice.html b/sample/doc/invoice/CreateInvoice.html index a42146f9..4f80c2ff 100644 --- a/sample/doc/invoice/CreateInvoice.html +++ b/sample/doc/invoice/CreateInvoice.html @@ -1,4 +1,4 @@ -invoice/CreateInvoice
sample/invoice/CreateInvoice.php
<?php

Create Invoice Sample

+invoice/CreateInvoice
invoice/CreateInvoice.php
<?php

Create Invoice Sample

This sample code demonstrate how you can create an invoice.

require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Invoice; diff --git a/sample/doc/invoice/GetInvoice.html b/sample/doc/invoice/GetInvoice.html index bee95b8d..66741090 100644 --- a/sample/doc/invoice/GetInvoice.html +++ b/sample/doc/invoice/GetInvoice.html @@ -1,4 +1,4 @@ -invoice/GetInvoice
sample/invoice/GetInvoice.php
<?php

Get Invoice Sample

+invoice/GetInvoice
invoice/GetInvoice.php
<?php

Get Invoice Sample

This sample code demonstrate how you can retrieve an invoice.

require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Invoice; diff --git a/sample/doc/invoice/ListInvoice.html b/sample/doc/invoice/ListInvoice.html index e2fbdd07..af7d80d2 100644 --- a/sample/doc/invoice/ListInvoice.html +++ b/sample/doc/invoice/ListInvoice.html @@ -1,4 +1,4 @@ -invoice/ListInvoice
sample/invoice/ListInvoice.php
<?php

List Invoices Sample

+invoice/ListInvoice
invoice/ListInvoice.php
<?php

List Invoices Sample

This sample code demonstrate how you can get all invoice from history.

require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Invoice; diff --git a/sample/doc/invoice/RemindInvoice.html b/sample/doc/invoice/RemindInvoice.html index 29b477a2..3789b924 100644 --- a/sample/doc/invoice/RemindInvoice.html +++ b/sample/doc/invoice/RemindInvoice.html @@ -1,4 +1,4 @@ -invoice/RemindInvoice
sample/invoice/RemindInvoice.php
<?php

Remind Invoice Sample

+invoice/RemindInvoice
invoice/RemindInvoice.php
<?php

Remind Invoice Sample

This sample code demonstrate how you can remind an invoice to the payer

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/invoice/SendInvoice.html b/sample/doc/invoice/SendInvoice.html index 4b8a5de0..2bae56ba 100644 --- a/sample/doc/invoice/SendInvoice.html +++ b/sample/doc/invoice/SendInvoice.html @@ -1,4 +1,4 @@ -invoice/SendInvoice
sample/invoice/SendInvoice.php
<?php

Create Invoice Sample

+invoice/SendInvoice
invoice/SendInvoice.php
<?php

Create Invoice Sample

This sample code demonstrate how you can send a legitimate invoice to the payer

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payment-experience/CreateWebProfile.html b/sample/doc/payment-experience/CreateWebProfile.html new file mode 100644 index 00000000..8742c22b --- /dev/null +++ b/sample/doc/payment-experience/CreateWebProfile.html @@ -0,0 +1,20 @@ +payment-experience/CreateWebProfile
payment-experience/CreateWebProfile.php
<?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;
\ No newline at end of file diff --git a/sample/doc/payment-experience/DeleteWebProfile.html b/sample/doc/payment-experience/DeleteWebProfile.html new file mode 100644 index 00000000..33427fe8 --- /dev/null +++ b/sample/doc/payment-experience/DeleteWebProfile.html @@ -0,0 +1,20 @@ +payment-experience/DeleteWebProfile
payment-experience/DeleteWebProfile.php
<?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());
\ No newline at end of file diff --git a/sample/doc/payment-experience/GetWebProfile.html b/sample/doc/payment-experience/GetWebProfile.html new file mode 100644 index 00000000..8c6577a1 --- /dev/null +++ b/sample/doc/payment-experience/GetWebProfile.html @@ -0,0 +1,21 @@ +payment-experience/GetWebProfile
payment-experience/GetWebProfile.php
<?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;
\ No newline at end of file diff --git a/sample/doc/payment-experience/ListWebProfiles.html b/sample/doc/payment-experience/ListWebProfiles.html new file mode 100644 index 00000000..b6c5e826 --- /dev/null +++ b/sample/doc/payment-experience/ListWebProfiles.html @@ -0,0 +1,23 @@ +payment-experience/ListWebProfiles
payment-experience/ListWebProfiles.php
<?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;
\ No newline at end of file diff --git a/sample/doc/payment-experience/PartiallyUpdateWebProfile.html b/sample/doc/payment-experience/PartiallyUpdateWebProfile.html new file mode 100644 index 00000000..827494cc --- /dev/null +++ b/sample/doc/payment-experience/PartiallyUpdateWebProfile.html @@ -0,0 +1,29 @@ +payment-experience/PartiallyUpdateWebProfile
payment-experience/PartiallyUpdateWebProfile.php
<?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);
\ No newline at end of file diff --git a/sample/doc/payment-experience/UpdateWebProfile.html b/sample/doc/payment-experience/UpdateWebProfile.html new file mode 100644 index 00000000..415433ab --- /dev/null +++ b/sample/doc/payment-experience/UpdateWebProfile.html @@ -0,0 +1,19 @@ +payment-experience/UpdateWebProfile
payment-experience/UpdateWebProfile.php
<?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);
\ No newline at end of file diff --git a/sample/doc/payments/AuthorizationCapture.html b/sample/doc/payments/AuthorizationCapture.html index 0b79a7b2..8616eda7 100644 --- a/sample/doc/payments/AuthorizationCapture.html +++ b/sample/doc/payments/AuthorizationCapture.html @@ -1,4 +1,4 @@ -payments/AuthorizationCapture
sample/payments/AuthorizationCapture.php
<?php

AuthorizationCapture

+payments/AuthorizationCapture
payments/AuthorizationCapture.php
<?php

AuthorizationCapture

This sample code demonstrates how you can capture a previously authorized payment. API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/CreateFuturePayment.html b/sample/doc/payments/CreateFuturePayment.html index b502fbfb..1b435e69 100644 --- a/sample/doc/payments/CreateFuturePayment.html +++ b/sample/doc/payments/CreateFuturePayment.html @@ -1,4 +1,4 @@ -payments/CreateFuturePayment
sample/payments/CreateFuturePayment.php
<?php

Create Payment using PayPal as payment method

+payments/CreateFuturePayment
payments/CreateFuturePayment.php
<?php

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

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/CreatePayment.html b/sample/doc/payments/CreatePayment.html index d40afef7..775bcd44 100644 --- a/sample/doc/payments/CreatePayment.html +++ b/sample/doc/payments/CreatePayment.html @@ -1,4 +1,4 @@ -payments/CreatePayment
sample/payments/CreatePayment.php
<?php

CreatePaymentSample

+payments/CreatePayment
payments/CreatePayment.php
<?php

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 @@ -payments/CreatePaymentUsingPayPal

sample/payments/CreatePaymentUsingPayPal.php
<?php

Create Payment using PayPal as payment method

+payments/CreatePaymentUsingPayPal
payments/CreatePaymentUsingPayPal.php
<?php

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

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/CreatePaymentUsingSavedCard.html b/sample/doc/payments/CreatePaymentUsingSavedCard.html index d42ff49c..9811e943 100644 --- a/sample/doc/payments/CreatePaymentUsingSavedCard.html +++ b/sample/doc/payments/CreatePaymentUsingSavedCard.html @@ -1,4 +1,4 @@ -payments/CreatePaymentUsingSavedCard
sample/payments/CreatePaymentUsingSavedCard.php
<?php

Create payment using a saved credit card

+payments/CreatePaymentUsingSavedCard
payments/CreatePaymentUsingSavedCard.php
<?php

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

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/ExecutePayment.html b/sample/doc/payments/ExecutePayment.html index bc641620..65521129 100644 --- a/sample/doc/payments/ExecutePayment.html +++ b/sample/doc/payments/ExecutePayment.html @@ -1,4 +1,4 @@ -payments/ExecutePayment
sample/payments/ExecutePayment.php
<?php

Execute Payment Sample

+payments/ExecutePayment
payments/ExecutePayment.php
<?php

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 @@ -payments/GetAuthorization

sample/payments/GetAuthorization.php
<?php

GetAuthorization

+payments/GetAuthorization
payments/GetAuthorization.php
<?php

GetAuthorization

This sample code demonstrates how you can get details of an authorized payment. API used: /v1/payments/authorization/<$authorizationId>

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/GetCapture.html b/sample/doc/payments/GetCapture.html index 3a3869e4..3a56b1bb 100644 --- a/sample/doc/payments/GetCapture.html +++ b/sample/doc/payments/GetCapture.html @@ -1,4 +1,4 @@ -payments/GetCapture
sample/payments/GetCapture.php
<?php

GetCapture

+payments/GetCapture
payments/GetCapture.php
<?php

GetCapture

This sample code demonstrates how you can lookup the details of a captured payment. API used: /v1/payments/capture/<$captureId>

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/GetPayment.html b/sample/doc/payments/GetPayment.html index fc3fdaa9..590721d3 100644 --- a/sample/doc/payments/GetPayment.html +++ b/sample/doc/payments/GetPayment.html @@ -1,4 +1,4 @@ -payments/GetPayment
sample/payments/GetPayment.php
<?php

GetPaymentSample

+payments/GetPayment
payments/GetPayment.php
<?php

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 @@ -payments/ListPayments

sample/payments/ListPayments.php
<?php

GetPaymentList

+payments/ListPayments
payments/ListPayments.php
<?php

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 @@ -payments/Reauthorization

sample/payments/Reauthorization.php
<?php

Reauthorization Sample

+payments/Reauthorization
payments/Reauthorization.php
<?php

Reauthorization Sample

This sample code demonstrates how you can reauthorize a PayPal account payment. API used: v1/payments/authorization/{authorization_id}/reauthorize

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/RefundCapture.html b/sample/doc/payments/RefundCapture.html index 272b6776..c74e0b96 100644 --- a/sample/doc/payments/RefundCapture.html +++ b/sample/doc/payments/RefundCapture.html @@ -1,4 +1,4 @@ -payments/RefundCapture
sample/payments/RefundCapture.php
<?php

Refund Capture Sample

+payments/RefundCapture
payments/RefundCapture.php
<?php

Refund Capture Sample

This sample code demonstrates how you can process a refund on a Captured transaction. API used: /v1/payments/capture/{}/refund

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/payments/VoidAuthorization.html b/sample/doc/payments/VoidAuthorization.html index ae3aa7a8..af144689 100644 --- a/sample/doc/payments/VoidAuthorization.html +++ b/sample/doc/payments/VoidAuthorization.html @@ -1,4 +1,4 @@ -payments/VoidAuthorization
sample/payments/VoidAuthorization.php
<?php

VoidAuthorization

+payments/VoidAuthorization
payments/VoidAuthorization.php
<?php

VoidAuthorization

This sample code demonstrates how you can void an authorized payment. API used: /v1/payments/authorization/<{authorizationid}>/void"

require __DIR__ . '/../bootstrap.php'; diff --git a/sample/doc/sale/GetSale.html b/sample/doc/sale/GetSale.html index 357eb883..1ef8ebdf 100644 --- a/sample/doc/sale/GetSale.html +++ b/sample/doc/sale/GetSale.html @@ -1,4 +1,4 @@ -sale/GetSale
sample/sale/GetSale.php
<?php

Get Sale sample

+sale/GetSale
sale/GetSale.php
<?php

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/RefundSale

sample/sale/RefundSale.php
<?php

Sale Refund Sample

+sale/RefundSale
sale/RefundSale.php
<?php

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 @@ -vault/CreateCreditCard

sample/vault/CreateCreditCard.php
<?php

Create Credit Card Sample

+vault/CreateCreditCard
vault/CreateCreditCard.php
<?php

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 @@ -vault/DeleteCreditCard

sample/vault/DeleteCreditCard.php
<?php

Delete CreditCard Sample

+vault/DeleteCreditCard
vault/DeleteCreditCard.php
<?php

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

Get Credit Card Sample

+vault/GetCreditCard
vault/GetCreditCard.php
<?php

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

+
+ + +
+

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); + } +}