diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index ce58565..6b7f00c 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -438,6 +438,30 @@ class Payment extends ResourceModel return $ret; } + /** + * Partially update a payment resource by by passing the payment_id in the request URI. In addition, pass a patch_request_object in the body of the request JSON that specifies the operation to perform, path of the target location, and new value to apply. Please note that it is not possible to use patch after execute has been called. + * + * @param PatchRequest $patchRequest + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return boolean + */ + public function update($patchRequest, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($patchRequest, 'patchRequest'); + $payLoad = $patchRequest->toJSON(); + self::executeCall( + "/v1/payments/payment/{$this->getId()}", + "PATCH", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + /** * Executes the payment (after approved by the Payer) associated with this resource when the payment method is PayPal. * diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 8b71c80..fbc2bdb 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -2807,6 +2807,81 @@ 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": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/UpdatePayment.php", + "projectPath": "payments/UpdatePayment.php", + "targetPath": "payments/UpdatePayment", + "pageTitle": "payments/UpdatePayment", + "title": "UpdatePayment" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Update Payment Sample", + "slug": "update-payment-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "NOTE", + "slug": "note" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 4, + "title": "Create a Patch Request", + "slug": "create-a-patch-request" + }, + "depth": 4 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Update payment", + "slug": "update-payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Getting Updated Payment Object", + "slug": "getting-updated-payment-object" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] + } + ] }, { "type": "file", "data": { diff --git a/sample/doc/payments/UpdatePayment.html b/sample/doc/payments/UpdatePayment.html new file mode 100644 index 0000000..f40569f --- /dev/null +++ b/sample/doc/payments/UpdatePayment.html @@ -0,0 +1,95 @@ +
This is how the data would look like: + [ + { + "op": "replace", + "path": "/transactions/0/amount", + "value": { + "total": "25.00", + "currency": "USD", + "details": { + "subtotal": "17.50", + "shipping": "6.20", + "tax": "1.30" + } + } + }, + { + "op": "add", + "path": "/transactions/0/item_list/shipping_address", + "value": { + "recipient_name": "Gruneberg, Anna", + "line1": "52 N Main St", + "city": "San Jose", + "postal_code": "95112", + "country_code": "US", + "state": "CA" + } + } + ]
Update payment object by calling the
+static update method
+on the Payment class by passing a valid
+Payment ID
+(See bootstrap.php for more on ApiContext)
The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $payment->getLinks() +method
Update Payment Sample
+This sample code demonstrate how you can +update a Payment resources +you've created using the Payments API.
+NOTE
+Note that it can only be updated before the execute is done. Once, the payment is executed it is not +possible to udpate that. +Docs: https://developer.paypal.com/webapps/developer/docs/api/#update-a-payment-resource +API used: PATCH /v1/payments/payment/