diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php index 2a98fbb..8499c31 100644 --- a/lib/PayPal/Api/CreditCard.php +++ b/lib/PayPal/Api/CreditCard.php @@ -3,9 +3,11 @@ namespace PayPal\Api; use PayPal\Common\PayPalResourceModel; -use PayPal\Validation\ArgumentValidator; -use PayPal\Rest\ApiContext; use PayPal\Transport\PayPalRestCall; +use PayPal\Validation\ArgumentValidator; +use PayPal\Api\CreditCardList; +use PayPal\Rest\ApiContext; +use PayPal\Transport\PPRestCall; /** * Class CreditCard @@ -24,10 +26,14 @@ use PayPal\Transport\PayPalRestCall; * @property string last_name * @property \PayPal\Api\Address billing_address * @property string external_customer_id + * @property string merchant_id + * @property string payer_id + * @property string external_card_id * @property string state - * @property string valid_until * @property string create_time * @property string update_time + * @property string valid_until + * @property \PayPal\Api\Links[] links */ class CreditCard extends PayPalResourceModel { @@ -78,7 +84,8 @@ class CreditCard extends PayPalResourceModel } /** - * Type of the Card (eg. Visa, Mastercard, etc.). + * Type of the Card. Currently supporting Visa, Mastercard, Amex, Discover and Maestro + * Valid Values: ["visa", "mastercard", "amex", "discover", "maestro"] * * @param string $type * @@ -91,7 +98,7 @@ class CreditCard extends PayPalResourceModel } /** - * Type of the Card (eg. Visa, Mastercard, etc.). + * Type of the Card. Currently supporting Visa, Mastercard, Amex, Discover and Maestro * * @return string */ @@ -261,6 +268,75 @@ class CreditCard extends PayPalResourceModel return $this->external_customer_id; } + /** + * A user provided, optional convenvience field that functions as a unique identifier for the merchant on behalf of whom this credit card is being stored for. Note that this has no relation to PayPal merchant id + * + * @param string $merchant_id + * + * @return $this + */ + public function setMerchantId($merchant_id) + { + $this->merchant_id = $merchant_id; + return $this; + } + + /** + * A user provided, optional convenvience field that functions as a unique identifier for the merchant on behalf of whom this credit card is being stored for. Note that this has no relation to PayPal merchant id + * + * @return string + */ + public function getMerchantId() + { + return $this->merchant_id; + } + + /** + * A unique identifier that you can assign and track when storing a credit card or using a stored credit card. This ID can help to avoid unintentional use or misuse of credit cards. This ID can be any value you would like to associate with the saved card, such as a UUID, username, or email address. Required when using a stored credit card if a payer_id was originally provided when storing the credit card in vault. + * @deprecated This is being deprecated in favor of the `external_customer_id` property. + * @param string $payer_id + * + * @return $this + */ + public function setPayerId($payer_id) + { + $this->payer_id = $payer_id; + return $this; + } + + /** + * A unique identifier that you can assign and track when storing a credit card or using a stored credit card. This ID can help to avoid unintentional use or misuse of credit cards. This ID can be any value you would like to associate with the saved card, such as a UUID, username, or email address. Required when using a stored credit card if a payer_id was originally provided when storing the credit card in vault. + * @deprecated This is being deprecated in favor of the `external_customer_id` property. + * @return string + */ + public function getPayerId() + { + return $this->payer_id; + } + + /** + * A unique identifier of the bank account resource. Generated and provided by the facilitator so it can be used to restrict the usage of the bank account to the specific merchant. + * + * @param string $external_card_id + * + * @return $this + */ + public function setExternalCardId($external_card_id) + { + $this->external_card_id = $external_card_id; + return $this; + } + + /** + * A unique identifier of the bank account resource. Generated and provided by the facilitator so it can be used to restrict the usage of the bank account to the specific merchant. + * + * @return string + */ + public function getExternalCardId() + { + return $this->external_card_id; + } + /** * State of the funding instrument. * Valid Values: ["expired", "ok"] @@ -285,6 +361,52 @@ class CreditCard extends PayPalResourceModel return $this->state; } + /** + * Resource creation time as ISO8601 date-time format (ex: 1994-11-05T13:15:30Z) that indicates creation time. + * + * @param string $create_time + * + * @return $this + */ + public function setCreateTime($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Resource creation time as ISO8601 date-time format (ex: 1994-11-05T13:15:30Z) that indicates creation time. + * + * @return string + */ + public function getCreateTime() + { + return $this->create_time; + } + + /** + * Resource creation time as ISO8601 date-time format (ex: 1994-11-05T13:15:30Z) that indicates the updation time. + * + * @param string $update_time + * + * @return $this + */ + public function setUpdateTime($update_time) + { + $this->update_time = $update_time; + return $this; + } + + /** + * Resource creation time as ISO8601 date-time format (ex: 1994-11-05T13:15:30Z) that indicates the updation time. + * + * @return string + */ + public function getUpdateTime() + { + return $this->update_time; + } + /** * Date/Time until this resource can be used fund a payment. * @@ -308,52 +430,6 @@ class CreditCard extends PayPalResourceModel return $this->valid_until; } - /** - * Time the resource was created in UTC ISO8601 format. - * - * @param string $create_time - * - * @return $this - */ - public function setCreateTime($create_time) - { - $this->create_time = $create_time; - return $this; - } - - /** - * Time the resource was created in UTC ISO8601 format. - * - * @return string - */ - public function getCreateTime() - { - return $this->create_time; - } - - /** - * Time the resource was created in UTC ISO8601 format. - * - * @param string $update_time - * - * @return $this - */ - public function setUpdateTime($update_time) - { - $this->update_time = $update_time; - return $this; - } - - /** - * Time the resource was created in UTC ISO8601 format. - * - * @return string - */ - public function getUpdateTime() - { - return $this->update_time; - } - /** * Creates a new Credit Card Resource (aka Tokenize). * @@ -448,4 +524,43 @@ class CreditCard extends PayPalResourceModel return $this; } + /** + * Retrieves a list of Credit Card resources. + * + * @param array $params + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return CreditCardList + */ + public static function all($params, $apiContext = null, $restCall = null) + { + if (is_null($params)) { + $params = array(); + } + ArgumentValidator::validate($params, 'params'); + $payLoad = ""; + $allowedParams = array( + 'page_size' => 1, + 'page' => 1, + 'start_time' => 1, + 'end_time' => 1, + 'sort_order' => 1, + 'sort_by' => 1, + 'merchant_id' => 1, + 'external_card_id' => 1, + 'external_customer_id' => 1, + ); + $json = self::executeCall( + "/v1/vault/credit-cards" . "?" . http_build_query(array_intersect_key($params, $allowedParams)), + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new CreditCardList(); + $ret->fromJson($json); + return $ret; + } + } diff --git a/lib/PayPal/Api/CreditCardList.php b/lib/PayPal/Api/CreditCardList.php index fa92e9e..97ba6aa 100644 --- a/lib/PayPal/Api/CreditCardList.php +++ b/lib/PayPal/Api/CreditCardList.php @@ -2,7 +2,7 @@ namespace PayPal\Api; -use PayPal\Common\PayPalModel; +use PayPal\Common\PayPalResourceModel; /** * Class CreditCardList @@ -11,22 +11,23 @@ use PayPal\Common\PayPalModel; * * @package PayPal\Api * - * @property \PayPal\Api\CreditCard[] credit_cards - * @property int count - * @property string next_id + * @property \PayPal\Api\CreditCard[] items + * @property \PayPal\Api\Links[] links + * @property int total_items + * @property int total_pages */ -class CreditCardList extends PayPalModel +class CreditCardList extends PayPalResourceModel { /** * A list of credit card resources * - * @param \PayPal\Api\CreditCard[] $credit_cards + * @param \PayPal\Api\CreditCard[] $items * * @return $this */ - public function setCreditCards($credit_cards) + public function setItems($items) { - $this->{"credit-cards"} = $credit_cards; + $this->items = $items; return $this; } @@ -35,85 +36,85 @@ class CreditCardList extends PayPalModel * * @return \PayPal\Api\CreditCard[] */ - public function getCreditCards() + public function getItems() { - return $this->{"credit-cards"}; + return $this->items; } /** - * Append CreditCards to the list. + * Append Items to the list. * * @param \PayPal\Api\CreditCard $creditCard * @return $this */ - public function addCreditCard($creditCard) + public function addItem($creditCard) { - if (!$this->getCreditCards()) { - return $this->setCreditCards(array($creditCard)); + if (!$this->getItems()) { + return $this->setItems(array($creditCard)); } else { - return $this->setCreditCards( - array_merge($this->getCreditCards(), array($creditCard)) + return $this->setItems( + array_merge($this->getItems(), array($creditCard)) ); } } /** - * Remove CreditCards from the list. + * Remove Items from the list. * * @param \PayPal\Api\CreditCard $creditCard * @return $this */ - public function removeCreditCard($creditCard) + public function removeItem($creditCard) { - return $this->setCreditCards( - array_diff($this->getCreditCards(), array($creditCard)) + return $this->setItems( + array_diff($this->getItems(), array($creditCard)) ); } /** - * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. + * Total number of items present in the given list. Note that the number of items might be larger than the records in the current page. * - * @param int $count + * @param int $total_items * * @return $this */ - public function setCount($count) + public function setTotalItems($total_items) { - $this->count = $count; + $this->total_items = $total_items; return $this; } /** - * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. + * Total number of items present in the given list. Note that the number of items might be larger than the records in the current page. * * @return int */ - public function getCount() + public function getTotalItems() { - return $this->count; + return $this->total_items; } /** - * Identifier of the next element to get the next range of results. + * Total number of pages that exist, for the total number of items, with the given page size. * - * @param string $next_id + * @param int $total_pages * * @return $this */ - public function setNextId($next_id) + public function setTotalPages($total_pages) { - $this->next_id = $next_id; + $this->total_pages = $total_pages; return $this; } /** - * Identifier of the next element to get the next range of results. + * Total number of pages that exist, for the total number of items, with the given page size. * - * @return string + * @return int */ - public function getNextId() + public function getTotalPages() { - return $this->next_id; + return $this->total_pages; } } diff --git a/lib/PayPal/Api/Patch.php b/lib/PayPal/Api/Patch.php index 9420a0e..739ff9c 100644 --- a/lib/PayPal/Api/Patch.php +++ b/lib/PayPal/Api/Patch.php @@ -19,8 +19,8 @@ use PayPal\Common\PayPalModel; class Patch extends PayPalModel { /** - * Patch operation to perform.Value required for add & remove operation can be any JSON value. - * Valid Values: ["add", "remove", "replace"] + * The operation to perform. + * Valid Values: ["add", "remove", "replace", "move", "copy", "test"] * * @param string $op * @@ -33,7 +33,7 @@ class Patch extends PayPalModel } /** - * Patch operation to perform.Value required for add & remove operation can be any JSON value. + * The operation to perform. * * @return string */ @@ -43,7 +43,7 @@ class Patch extends PayPalModel } /** - * string containing a JSON-Pointer value that references a location within the target document (the target location) where the operation is performed. + * String containing a JSON-Pointer value that references a location within the target document where the operation is performed. * * @param string $path * @@ -56,7 +56,7 @@ class Patch extends PayPalModel } /** - * string containing a JSON-Pointer value that references a location within the target document (the target location) where the operation is performed. + * String containing a JSON-Pointer value that references a location within the target document where the operation is performed. * * @return string */ @@ -89,7 +89,7 @@ class Patch extends PayPalModel } /** - * A string containing a JSON Pointer value that references the location in the target document to move the value from. + * 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 * @@ -102,7 +102,7 @@ class Patch extends PayPalModel } /** - * A string containing a JSON Pointer value that references the location in the target document to move the value from. + * 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 */ diff --git a/sample/billing/CreateBillingAgreementWithCreditCard.php b/sample/billing/CreateBillingAgreementWithCreditCard.php index 022a50b..f0f1465 100644 --- a/sample/billing/CreateBillingAgreementWithCreditCard.php +++ b/sample/billing/CreateBillingAgreementWithCreditCard.php @@ -56,7 +56,7 @@ $agreement = new Agreement(); $agreement->setName('DPRP') ->setDescription('Payment with credit Card') - ->setStartDate('2015-06-17T9:45:04Z'); + ->setStartDate('2019-06-17T9:45:04Z'); // Add Plan ID // Please note that the plan Id should be only set in this case. diff --git a/sample/billing/CreateBillingAgreementWithPayPal.php b/sample/billing/CreateBillingAgreementWithPayPal.php index 046f302..a22bed0 100644 --- a/sample/billing/CreateBillingAgreementWithPayPal.php +++ b/sample/billing/CreateBillingAgreementWithPayPal.php @@ -39,7 +39,7 @@ $agreement = new Agreement(); $agreement->setName('Base Agreement') ->setDescription('Basic Agreement') - ->setStartDate('2015-06-17T9:45:04Z'); + ->setStartDate('2019-06-17T9:45:04Z'); // Add Plan ID // Please note that the plan Id should be only set in this case. diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 44f4ed2..c955ee2 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -30,7 +30,29 @@ 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 "pageTitle": "billing/CreateBillingAgreementWithCreditCard", "title": "CreateBillingAgreementWithCreditCard" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Billing Agreement with Credit Card as Payment Source", + "slug": "create-billing-agreement-with-credit-card-as-payment-source" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Agreement", + "slug": "create-agreement" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -48,7 +70,37 @@ 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 "pageTitle": "billing/CreateBillingAgreementWithPayPal", "title": "CreateBillingAgreementWithPayPal" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Billing Agreement with PayPal as Payment Source", + "slug": "create-billing-agreement-with-paypal-as-payment-source" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Agreement", + "slug": "create-agreement" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -66,7 +118,45 @@ 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 "pageTitle": "billing/CreatePlan", "title": "CreatePlan" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Plan Sample", + "slug": "create-plan-sample" + }, + "depth": 1 + }, { + "type": "heading", + "data": { + "level": 1, + "title": "Basic Information", + "slug": "basic-information" + }, + "depth": 1 + }, { + "type": "heading", + "data": { + "level": 1, + "title": "Payment definitions for this billing plan.", + "slug": "payment-definitions-for-this-billing-plan" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Plan", + "slug": "create-plan" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -246,7 +336,29 @@ 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 "pageTitle": "billing/UpdatePlan", "title": "UpdatePlan" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Update a plan", + "slug": "update-a-plan" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Making Plan Active", + "slug": "making-plan-active" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -346,29 +458,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 "pageTitle": "invoice/GetInvoice", "title": "GetInvoice" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Get Invoice Sample", - "slug": "get-invoice-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Retrieve Invoice", - "slug": "retrieve-invoice" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -512,7 +602,53 @@ 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 "pageTitle": "invoice/UpdateInvoice", "title": "UpdateInvoice" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Update Invoice Sample", + "slug": "update-invoice-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Update Invoice", + "slug": "update-invoice" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "NOTE: These are the work-around added to the", + "slug": "note-these-are-the-work-around-added-to-the" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Update Invoice", + "slug": "update-invoice" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Retrieve Invoice", + "slug": "retrieve-invoice" + }, + "depth": 3 + } + ] + } + ] } ] }, { @@ -576,18 +712,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 "pageTitle": "lipp/ObtainUserConsent", "title": "ObtainUserConsent" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Get User Consent URL", - "slug": "get-user-consent-url" - }, - "depth": 3 - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -605,18 +730,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 "pageTitle": "lipp/UserConsentRedirect", "title": "UserConsentRedirect" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "User Consent Response", - "slug": "user-consent-response" - }, - "depth": 3 - } - ] + "depth": 2 } ] }, { @@ -788,40 +902,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 "pageTitle": "notifications/ValidateWebhookEvent", "title": "ValidateWebhookEvent" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Validate Webhook", - "slug": "validate-webhook" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 2, - "title": "Received Body from Webhook", - "slug": "received-body-from-webhook" - }, - "depth": 2, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Validate Received Event Method", - "slug": "validate-received-event-method" - }, - "depth": 3 - } - ] - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1283,7 +1364,37 @@ 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 "pageTitle": "payments/ExecutePayment", "title": "ExecutePayment" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Execute Payment Sample", + "slug": "execute-payment-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Approval Status", + "slug": "approval-status" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment Execute", + "slug": "payment-execute" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1337,7 +1448,29 @@ 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 "pageTitle": "payments/GetPayment", "title": "GetPayment" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "GetPaymentSample", + "slug": "getpaymentsample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Retrieve payment", + "slug": "retrieve-payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1355,7 +1488,29 @@ 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 "pageTitle": "payments/ListPayments", "title": "ListPayments" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "GetPaymentList", + "slug": "getpaymentlist" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Retrieve payment", + "slug": "retrieve-payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1391,7 +1546,53 @@ 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 "pageTitle": "payments/OrderCapture", "title": "OrderCapture" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Capture Order Sample", + "slug": "capture-order-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Approval Status", + "slug": "approval-status" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Retrieve the order", + "slug": "retrieve-the-order" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Capture Object", + "slug": "create-capture-object" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Capture Order", + "slug": "capture-order" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1499,29 +1700,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 "pageTitle": "payments/OrderGet", "title": "OrderGet" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Get Order Sample", - "slug": "get-order-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Approval Status", - "slug": "approval-status" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1557,29 +1736,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 "pageTitle": "payments/RefundCapture", "title": "RefundCapture" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Refund Capture Sample", - "slug": "refund-capture-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Refund", - "slug": "refund" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1743,37 +1900,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 "pageTitle": "sale/GetSale", "title": "GetSale" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Get Sale sample", - "slug": "get-sale-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Get Sale From Created Payment", - "slug": "get-sale-from-created-payment" - }, - "depth": 3 - }, { - "type": "heading", - "data": { - "level": 3, - "title": "Retrieve the sale object", - "slug": "retrieve-the-sale-object" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1837,7 +1964,45 @@ 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 "pageTitle": "vault/CreateCreditCard", "title": "CreateCreditCard" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Credit Card Sample", + "slug": "create-credit-card-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "CreditCard", + "slug": "creditcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional Information", + "slug": "additional-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Save card", + "slug": "save-card" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1909,7 +2074,58 @@ 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 "pageTitle": "vault/GetCreditCard", "title": "GetCreditCard" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get Credit Card Sample", + "slug": "get-credit-card-sample" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/vault/ListCreditCards.php", + "projectPath": "vault/ListCreditCards.php", + "targetPath": "vault/ListCreditCards", + "pageTitle": "vault/ListCreditCards", + "title": "ListCreditCards" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "List Credit Card Sample", + "slug": "list-credit-card-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Parameters to Filter", + "slug": "parameters-to-filter" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { diff --git a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html index f5fb6f4..8db7105 100644 --- a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html +++ b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html @@ -50,7 +50,7 @@ define Plan information to create an agreement. Make sure the plan you are using $agreement->setName('DPRP') ->setDescription('Payment with credit Card') - ->setStartDate('2015-06-17T9:45:04Z');

Add Plan ID + ->setStartDate('2019-06-17T9:45:04Z');

Add Plan ID Please note that the plan Id should be only set in this case.

$plan = new Plan(); $plan->setId($createdPlan->getId()); $agreement->setPlan($plan);

Add Payer

$payer = new Payer(); diff --git a/sample/doc/billing/CreateBillingAgreementWithPayPal.html b/sample/doc/billing/CreateBillingAgreementWithPayPal.html index ec36690..82ece0c 100644 --- a/sample/doc/billing/CreateBillingAgreementWithPayPal.html +++ b/sample/doc/billing/CreateBillingAgreementWithPayPal.html @@ -33,7 +33,7 @@ define Plan information to create an agreement. Make sure the plan you are using $agreement->setName('Base Agreement') ->setDescription('Basic Agreement') - ->setStartDate('2015-06-17T9:45:04Z');

Add Plan ID + ->setStartDate('2019-06-17T9:45:04Z');

Add Plan ID Please note that the plan Id should be only set in this case.

$plan = new Plan(); $plan->setId($createdPlan->getId()); $agreement->setPlan($plan);

Add Payer

$payer = new Payer(); diff --git a/sample/doc/payments/GetPayment.html b/sample/doc/payments/GetPayment.html index 4041c9a..e440905 100644 --- a/sample/doc/payments/GetPayment.html +++ b/sample/doc/payments/GetPayment.html @@ -16,13 +16,8 @@ on the Payment class by passing a valid Payment ID (See bootstrap.php for more on ApiContext)

try { $payment = Payment::get($paymentId, $apiContext); -} catch (Exception $ex) { - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); +} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); exit(1); -} +}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment); -// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment); - -return $payment;
+return $payment; \ No newline at end of file diff --git a/sample/doc/vault/CreateCreditCard.html b/sample/doc/vault/CreateCreditCard.html index 20fb69b..6fd5db4 100644 --- a/sample/doc/vault/CreateCreditCard.html +++ b/sample/doc/vault/CreateCreditCard.html @@ -12,7 +12,15 @@ to be stored with PayPal.

->setExpireYear("2019") ->setCvv2("012") ->setFirstName("Joe") - ->setLastName("Shopper");

For Sample Purposes Only.

$request = clone $card;

Save card

+ ->setLastName("Shopper");

Additional Information

+

Now you can also store the information that could help you connect +your users with the stored credit cards. +All these three fields could be used for storing any information that could help merchant to point the card. +However, Ideally, MerchantId could be used to categorize stores, apps, websites, etc. +ExternalCardId could be used for uniquely identifying the card per MerchantId. So, combination of "MerchantId" and "ExternalCardId" should be unique. +ExternalCustomerId could be userId, user email, etc to group multiple cards per user.

$card->setMerchantId("MyStore1"); +$card->setExternalCardId("CardNumber123" . uniqid()); +$card->setExternalCustomerId("123123-myUser1@something.com");

For Sample Purposes Only.

$request = clone $card;

Save card

Creates the credit card as a resource in the PayPal vault. The response contains an 'id' that you can use to refer to it diff --git a/sample/doc/vault/ListCreditCards.html b/sample/doc/vault/ListCreditCards.html new file mode 100644 index 0000000..01c5f4b --- /dev/null +++ b/sample/doc/vault/ListCreditCards.html @@ -0,0 +1,21 @@ +vault/ListCreditCards

vault/ListCreditCards.php
<?php

List Credit Card Sample

+

The CreditCard resource allows you to +retrieve all previously saved CreditCards. +API called: '/v1/vault/credit-cards' +Documentation: https://developer.paypal.com/webapps/developer/docs/api/#list-credit-card-resources

Creating a Credit Card just in case

/** @var CreditCard $card */ +$card = require 'CreateCreditCard.php'; + +use PayPal\Api\CreditCard; + +/// ### List All Credit Cards

(See bootstrap.php for more on ApiContext)

try {

Parameters to Filter

+

There are many possible filters that you could apply to it. For complete list, please refere to developer docs at above link.

$params = array( + "sort_by" => "create_time", + "sort_order" => "desc", + "merchant_id" => "MyStore1" // Filtering by MerchantId set during CreateCreditCard. + ); + $cards = CreditCard::all($params, $apiContext); +} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("List All Credit Cards", "CreditCardList", null, $params, $ex); + exit(1); +}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("List All Credit Cards", "CreditCardList", null, $params, $cards); + +return $card;
\ No newline at end of file diff --git a/sample/index.php b/sample/index.php index 545de4b..4035096 100644 --- a/sample/index.php +++ b/sample/index.php @@ -879,6 +879,17 @@ if (PHP_SAPI == 'cli') {
+
  • +
    +
    Credit Card - List All
    + +
    +
  • Credit Card - Update
    diff --git a/sample/vault/CreateCreditCard.php b/sample/vault/CreateCreditCard.php index 785ac83..e025b9a 100644 --- a/sample/vault/CreateCreditCard.php +++ b/sample/vault/CreateCreditCard.php @@ -22,6 +22,17 @@ $card->setType("visa") ->setFirstName("Joe") ->setLastName("Shopper"); +// ### Additional Information +// Now you can also store the information that could help you connect +// your users with the stored credit cards. +// All these three fields could be used for storing any information that could help merchant to point the card. +// However, Ideally, MerchantId could be used to categorize stores, apps, websites, etc. +// ExternalCardId could be used for uniquely identifying the card per MerchantId. So, combination of "MerchantId" and "ExternalCardId" should be unique. +// ExternalCustomerId could be userId, user email, etc to group multiple cards per user. +$card->setMerchantId("MyStore1"); +$card->setExternalCardId("CardNumber123" . uniqid()); +$card->setExternalCustomerId("123123-myUser1@something.com"); + // For Sample Purposes Only. $request = clone $card; diff --git a/sample/vault/ListCreditCards.php b/sample/vault/ListCreditCards.php new file mode 100644 index 0000000..8cd5d81 --- /dev/null +++ b/sample/vault/ListCreditCards.php @@ -0,0 +1,36 @@ + "create_time", + "sort_order" => "desc", + "merchant_id" => "MyStore1" // Filtering by MerchantId set during CreateCreditCard. + ); + $cards = CreditCard::all($params, $apiContext); +} catch (Exception $ex) { + // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY + ResultPrinter::printError("List All Credit Cards", "CreditCardList", null, $params, $ex); + exit(1); +} + +// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY + ResultPrinter::printResult("List All Credit Cards", "CreditCardList", null, $params, $cards); + +return $card; diff --git a/tests/PayPal/Test/Api/CreditCardListTest.php b/tests/PayPal/Test/Api/CreditCardListTest.php index 285d046..c52cb7d 100644 --- a/tests/PayPal/Test/Api/CreditCardListTest.php +++ b/tests/PayPal/Test/Api/CreditCardListTest.php @@ -18,7 +18,7 @@ class CreditCardListTest extends \PHPUnit_Framework_TestCase */ public static function getJson() { - return '{"credit-cards":' .CreditCardTest::getJson() . ',"count":123,"next_id":"TestSample"}'; + return '{"items":' .CreditCardTest::getJson() . ',"links":' .LinksTest::getJson() . ',"total_items":123,"total_pages":123}'; } /** @@ -39,9 +39,10 @@ class CreditCardListTest extends \PHPUnit_Framework_TestCase { $obj = new CreditCardList(self::getJson()); $this->assertNotNull($obj); - $this->assertNotNull($obj->getCreditCards()); - $this->assertNotNull($obj->getCount()); - $this->assertNotNull($obj->getNextId()); + $this->assertNotNull($obj->getItems()); + $this->assertNotNull($obj->getLinks()); + $this->assertNotNull($obj->getTotalItems()); + $this->assertNotNull($obj->getTotalPages()); $this->assertEquals(self::getJson(), $obj->toJson()); return $obj; } @@ -52,9 +53,10 @@ class CreditCardListTest extends \PHPUnit_Framework_TestCase */ public function testGetters($obj) { - $this->assertEquals($obj->getCreditCards(), CreditCardTest::getObject()); - $this->assertEquals($obj->getCount(), 123); - $this->assertEquals($obj->getNextId(), "TestSample"); + $this->assertEquals($obj->getItems(), CreditCardTest::getObject()); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + $this->assertEquals($obj->getTotalItems(), 123); + $this->assertEquals($obj->getTotalPages(), 123); } } diff --git a/tests/PayPal/Test/Api/CreditCardTest.php b/tests/PayPal/Test/Api/CreditCardTest.php index ba3a9ff..ace0002 100644 --- a/tests/PayPal/Test/Api/CreditCardTest.php +++ b/tests/PayPal/Test/Api/CreditCardTest.php @@ -2,7 +2,11 @@ namespace PayPal\Test\Api; -use PayPal\Common\PayPalModel; +use PayPal\Common\PayPalResourceModel; +use PayPal\Validation\ArgumentValidator; +use PayPal\Api\CreditCardList; +use PayPal\Rest\ApiContext; +use PayPal\Transport\PPRestCall; use PayPal\Api\CreditCard; /** @@ -18,7 +22,7 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase */ public static function getJson() { - return '{"id":"TestSample","number":"TestSample","type":"TestSample","expire_month":123,"expire_year":123,"cvv2":"TestSample","first_name":"TestSample","last_name":"TestSample","billing_address":' .AddressTest::getJson() . ',"external_customer_id":"TestSample","state":"TestSample","valid_until":"TestSample","links":' .LinksTest::getJson() . '}'; + return '{"id":"TestSample","number":"TestSample","type":"TestSample","expire_month":123,"expire_year":123,"cvv2":"TestSample","first_name":"TestSample","last_name":"TestSample","billing_address":' .AddressTest::getJson() . ',"external_customer_id":"TestSample","merchant_id":"TestSample","payer_id":"TestSample","external_card_id":"TestSample","state":"TestSample","create_time":"TestSample","update_time":"TestSample","valid_until":"TestSample","links":' .LinksTest::getJson() . '}'; } /** @@ -49,7 +53,12 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase $this->assertNotNull($obj->getLastName()); $this->assertNotNull($obj->getBillingAddress()); $this->assertNotNull($obj->getExternalCustomerId()); + $this->assertNotNull($obj->getMerchantId()); + $this->assertNotNull($obj->getPayerId()); + $this->assertNotNull($obj->getExternalCardId()); $this->assertNotNull($obj->getState()); + $this->assertNotNull($obj->getCreateTime()); + $this->assertNotNull($obj->getUpdateTime()); $this->assertNotNull($obj->getValidUntil()); $this->assertNotNull($obj->getLinks()); $this->assertEquals(self::getJson(), $obj->toJson()); @@ -72,9 +81,123 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase $this->assertEquals($obj->getLastName(), "TestSample"); $this->assertEquals($obj->getBillingAddress(), AddressTest::getObject()); $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); + $this->assertEquals($obj->getMerchantId(), "TestSample"); + $this->assertEquals($obj->getPayerId(), "TestSample"); + $this->assertEquals($obj->getExternalCardId(), "TestSample"); $this->assertEquals($obj->getState(), "TestSample"); + $this->assertEquals($obj->getCreateTime(), "TestSample"); + $this->assertEquals($obj->getUpdateTime(), "TestSample"); $this->assertEquals($obj->getValidUntil(), "TestSample"); $this->assertEquals($obj->getLinks(), LinksTest::getObject()); } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testCreate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->create($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + CreditCardTest::getJson() + )); + + $result = $obj->get("creditCardId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testDelete($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + + $result = $obj->delete($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testUpdate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + $patchRequest = PatchRequestTest::getObject(); + + $result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testList($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + CreditCardListTest::getJson() + )); + $params = array(); + + $result = $obj->all($params, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } } diff --git a/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreateCCAgreement.json b/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreateCCAgreement.json index 99a5259..dfe2214 100755 --- a/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreateCCAgreement.json +++ b/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreateCCAgreement.json @@ -20,7 +20,7 @@ "body": { "name": "DPRP", "description": "Payment with credit Card ", - "start_date": "2015-06-17T9:45:04Z", + "start_date": "2019-06-17T9:45:04Z", "plan": { "id": "P-1WJ68935LL406420PUTENA2I" }, diff --git a/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreatePayPalAgreement.json b/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreatePayPalAgreement.json index 4c1ce87..0e498fc 100755 --- a/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreatePayPalAgreement.json +++ b/tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreatePayPalAgreement.json @@ -20,7 +20,7 @@ "body": { "name": "Base Agreement", "description": "Basic agreement", - "start_date": "2015-06-17T9:45:04Z", + "start_date": "2019-06-17T9:45:04Z", "plan": { "id": "P-1WJ68935LL406420PUTENA2I" },