From 47cd78172ce9207c4cf3c75af9895da867a01321 Mon Sep 17 00:00:00 2001 From: japatel Date: Wed, 4 Feb 2015 15:54:30 -0600 Subject: [PATCH] Order API Support - Added Order API Support - Updated Sample Code to demonstrate - Updated Sample Docs - Fixes #237 --- lib/PayPal/Api/Order.php | 293 +++--- sample/doc/assets/behavior.js | 831 ++++++++++++++---- .../CreateBillingAgreementWithPayPal.html | 2 +- sample/doc/payments/ExecutePayment.html | 19 +- sample/doc/payments/OrderAuthorize.html | 37 + sample/doc/payments/OrderCapture.html | 37 + .../payments/OrderCreateForAuthorization.html | 77 ++ .../doc/payments/OrderCreateForCapture.html | 77 ++ sample/doc/payments/OrderCreateForVoid.html | 77 ++ .../doc/payments/OrderCreateUsingPayPal.html | 77 ++ sample/doc/payments/OrderDoVoid.html | 29 + sample/doc/payments/OrderGet.html | 26 + sample/index.php | 125 +++ sample/payments/ExecutePayment.php | 22 +- sample/payments/OrderAuthorize.php | 51 ++ sample/payments/OrderCapture.php | 51 ++ .../payments/OrderCreateForAuthorization.php | 112 +++ sample/payments/OrderCreateForCapture.php | 112 +++ sample/payments/OrderCreateForVoid.php | 112 +++ sample/payments/OrderCreateUsingPayPal.php | 112 +++ sample/payments/OrderDoVoid.php | 40 + sample/payments/OrderGet.php | 32 + 22 files changed, 2045 insertions(+), 306 deletions(-) create mode 100644 sample/doc/payments/OrderAuthorize.html create mode 100644 sample/doc/payments/OrderCapture.html create mode 100644 sample/doc/payments/OrderCreateForAuthorization.html create mode 100644 sample/doc/payments/OrderCreateForCapture.html create mode 100644 sample/doc/payments/OrderCreateForVoid.html create mode 100644 sample/doc/payments/OrderCreateUsingPayPal.html create mode 100644 sample/doc/payments/OrderDoVoid.html create mode 100644 sample/doc/payments/OrderGet.html create mode 100644 sample/payments/OrderAuthorize.php create mode 100644 sample/payments/OrderCapture.php create mode 100644 sample/payments/OrderCreateForAuthorization.php create mode 100644 sample/payments/OrderCreateForCapture.php create mode 100644 sample/payments/OrderCreateForVoid.php create mode 100644 sample/payments/OrderCreateUsingPayPal.php create mode 100644 sample/payments/OrderDoVoid.php create mode 100644 sample/payments/OrderGet.php diff --git a/lib/PayPal/Api/Order.php b/lib/PayPal/Api/Order.php index 9db965b..54761f8 100644 --- a/lib/PayPal/Api/Order.php +++ b/lib/PayPal/Api/Order.php @@ -2,8 +2,10 @@ namespace PayPal\Api; -use PayPal\Common\PayPalModel; +use PayPal\Common\PayPalResourceModel; use PayPal\Rest\ApiContext; +use PayPal\Transport\PayPalRestCall; +use PayPal\Validation\ArgumentValidator; /** * Class Order @@ -14,21 +16,20 @@ use PayPal\Rest\ApiContext; * * @property string id * @property string purchase_unit_reference_id - * @property string create_time - * @property string update_time * @property \PayPal\Api\Amount amount - * @property string payment_mode * @property string state * @property string reason_code + * @property string pending_reason * @property string protection_eligibility * @property string protection_eligibility_type - * @property \PayPal\Api\Links links + * @property string parent_payment + * @property string create_time + * @property string update_time */ -class Order extends PayPalModel +class Order extends PayPalResourceModel { /** * Identifier of the order transaction. - * * * @param string $id * @@ -51,8 +52,7 @@ class Order extends PayPalModel } /** - * Identifier to the purchase unit associated with this object - * + * Identifier to the purchase unit associated with this object. Obsolete. Use one in cart_base. * * @param string $purchase_unit_reference_id * @@ -65,7 +65,7 @@ class Order extends PayPalModel } /** - * Identifier to the purchase unit associated with this object + * Identifier to the purchase unit associated with this object. Obsolete. Use one in cart_base. * * @return string */ @@ -74,57 +74,8 @@ class Order extends PayPalModel return $this->purchase_unit_reference_id; } - /** - * 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 last updated 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 last updated in UTC ISO8601 format. - * - * @return string - */ - public function getUpdateTime() - { - return $this->update_time; - } - /** * Amount being collected. - * * * @param \PayPal\Api\Amount $amount * @@ -146,33 +97,10 @@ class Order extends PayPalModel return $this->amount; } - /** - * specifies payment mode of the transaction - * Valid Values: ["INSTANT_TRANSFER", "MANUAL_BANK_TRANSFER", "DELAYED_TRANSFER", "ECHECK"] - * - * @param string $payment_mode - * - * @return $this - */ - public function setPaymentMode($payment_mode) - { - $this->payment_mode = $payment_mode; - return $this; - } - - /** - * specifies payment mode of the transaction - * - * @return string - */ - public function getPaymentMode() - { - return $this->payment_mode; - } /** * State of the order transaction. - * Valid Values: ["PENDING", "COMPLETED", "REFUNDED", "PARTIALLY_REFUNDED"] + * Valid Values: ["pending", "completed", "refunded", "partially_refunded"] * * @param string $state * @@ -195,8 +123,8 @@ class Order extends PayPalModel } /** - * Reason code for the transaction state being Pending or Reversed. - * Valid Values: ["CHARGEBACK", "GUARANTEE", "BUYER_COMPLAINT", "REFUND", "UNCONFIRMED_SHIPPING_ADDRESS", "ECHECK", "INTERNATIONAL_WITHDRAWAL", "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION", "PAYMENT_REVIEW", "REGULATORY_REVIEW", "UNILATERAL", "VERIFICATION_REQUIRED"] + * Reason code for the transaction state being Pending or Reversed. This field will replace pending_reason field eventually + * Valid Values: ["PAYER_SHIPPING_UNCONFIRMED", "MULTI_CURRENCY", "RISK_REVIEW", "REGULATORY_REVIEW", "VERIFICATION_REQUIRED", "ORDER", "OTHER"] * * @param string $reason_code * @@ -209,7 +137,7 @@ class Order extends PayPalModel } /** - * Reason code for the transaction state being Pending or Reversed. + * Reason code for the transaction state being Pending or Reversed. This field will replace pending_reason field eventually * * @return string */ @@ -218,9 +146,33 @@ class Order extends PayPalModel return $this->reason_code; } + /** + * Reason code for the transaction state being Pending. Obsolete. Retained for backward compatability. Use reason_code field above instead. + * Valid Values: ["payer_shipping_unconfirmed", "multi_currency", "risk_review", "regulatory_review", "verification_required", "order", "other"] + * + * @param string $pending_reason + * + * @return $this + */ + public function setPendingReason($pending_reason) + { + $this->pending_reason = $pending_reason; + return $this; + } + + /** + * Reason code for the transaction state being Pending. Obsolete. Retained for backward compatability. Use reason_code field above instead. + * + * @return string + */ + public function getPendingReason() + { + return $this->pending_reason; + } + /** * Protection Eligibility of the Payer - * Valid Values: ["ELIGIBLE", "PARTIALLY_ELIGIBLE", "INELIGIBLE"] + * Valid Values: ["ELIGIBLE", "PARTIALLY_ELIGIBLE", "INELIGIBLE"] * * @param string $protection_eligibility * @@ -244,7 +196,7 @@ class Order extends PayPalModel /** * Protection Eligibility Type of the Payer - * Valid Values: ["ELIGIBLE", "ITEM_NOT_RECEIVED_ELIGIBLE", "INELIGIBLE", "UNAUTHORIZED_PAYMENT_ELIGIBLE"] + * Valid Values: ["ELIGIBLE", "ITEM_NOT_RECEIVED_ELIGIBLE", "INELIGIBLE", "UNAUTHORIZED_PAYMENT_ELIGIBLE"] * * @param string $protection_eligibility_type * @@ -267,27 +219,172 @@ class Order extends PayPalModel } /** - * Sets Links - * + * ID of the Payment resource that this transaction is based on. * - * @param \PayPal\Api\Links $links - * + * @param string $parent_payment * @return $this */ - public function setLinks($links) + public function setParentPayment($parent_payment) { - $this->links = $links; + $this->parent_payment = $parent_payment; return $this; } /** - * Gets Links + * ID of the Payment resource that this transaction is based on. * - * @return \PayPal\Api\Links[] + * @return string */ - public function getLinks() + public function getParentPayment() { - return $this->links; + return $this->parent_payment; + } + + + /** + * 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 last updated 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 last updated in UTC ISO8601 format. + * + * @return string + */ + public function getUpdateTime() + { + return $this->update_time; + } + + /** + * Retrieve details about an order by passing the order_id in the request URI. + * + * @param string $orderId + * @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 Order + */ + public static function get($orderId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($orderId, 'orderId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/payments/orders/$orderId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new Order(); + $ret->fromJson($json); + return $ret; + } + + /** + * Capture a payment on an order by passing the order_id in the request URI. In addition, include the amount of the payment and indicate whether this is a final capture for the given authorization in the body of the request JSON. To issue this request, an original payment call must specify an intent of order. + * + * @param Capture $capture + * @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 Capture + */ + public function capture($capture, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($capture, 'capture'); + $payLoad = $capture->toJSON(); + $json = self::executeCall( + "/v1/payments/orders/{$this->getId()}/capture", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new Capture(); + $ret->fromJson($json); + return $ret; + } + + /** + * Void (cancel) an order by passing the order_id in the request URI. Note that an order cannot be voided if payment has already been partially or fully captured. + * + * @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 Order + */ + public function void($apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + $payLoad = ""; + $json = self::executeCall( + "/v1/payments/orders/{$this->getId()}/do-void", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Authorize an order by passing the order_id in the request URI. In addition, include an amount object in the body of the request JSON. + * + * @param Authorization $authorization Authorization Object with Amount value to be authorized + * @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 Authorization + */ + public function authorize($authorization, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($authorization, 'Authorization'); + $payLoad = $authorization->toJSON(); + $json = self::executeCall( + "/v1/payments/orders/{$this->getId()}/authorize", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new Authorization(); + $ret->fromJson($json); + return $ret; } } diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 4b31526..3668619 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -48,37 +48,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": "billing/CreateBillingAgreementWithPayPal", "title": "CreateBillingAgreementWithPayPal" }, - "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 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1010,14 +980,298 @@ 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/CreatePaymentUsingPayPal", "title": "CreatePaymentUsingPayPal" }, + "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/CreatePaymentUsingSavedCard.php", + "projectPath": "payments/CreatePaymentUsingSavedCard.php", + "targetPath": "payments/CreatePaymentUsingSavedCard", + "pageTitle": "payments/CreatePaymentUsingSavedCard", + "title": "CreatePaymentUsingSavedCard" + }, + "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/ExecutePayment.php", + "projectPath": "payments/ExecutePayment.php", + "targetPath": "payments/ExecutePayment", + "pageTitle": "payments/ExecutePayment", + "title": "ExecutePayment" + }, "depth": 2, "outline": [ { "type": "heading", "data": { "level": 1, - "title": "Create Payment using PayPal as payment method", - "slug": "create-payment-using-paypal-as-payment-method" + "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": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/GetAuthorization.php", + "projectPath": "payments/GetAuthorization.php", + "targetPath": "payments/GetAuthorization", + "pageTitle": "payments/GetAuthorization", + "title": "GetAuthorization" + }, + "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/GetCapture.php", + "projectPath": "payments/GetCapture.php", + "targetPath": "payments/GetCapture", + "pageTitle": "payments/GetCapture", + "title": "GetCapture" + }, + "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/GetPayment.php", + "projectPath": "payments/GetPayment.php", + "targetPath": "payments/GetPayment", + "pageTitle": "payments/GetPayment", + "title": "GetPayment" + }, + "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/ListPayments.php", + "projectPath": "payments/ListPayments.php", + "targetPath": "payments/ListPayments", + "pageTitle": "payments/ListPayments", + "title": "ListPayments" + }, + "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderAuthorize.php", + "projectPath": "payments/OrderAuthorize.php", + "targetPath": "payments/OrderAuthorize", + "pageTitle": "payments/OrderAuthorize", + "title": "OrderAuthorize" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Authorize Order Sample", + "slug": "authorize-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 Authorization Object", + "slug": "create-authorization-object" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Authorize Order", + "slug": "authorize-order" + }, + "depth": 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/OrderCapture.php", + "projectPath": "payments/OrderCapture.php", + "targetPath": "payments/OrderCapture", + "pageTitle": "payments/OrderCapture", + "title": "OrderCapture" + }, + "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": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderCreateForAuthorization.php", + "projectPath": "payments/OrderCreateForAuthorization.php", + "targetPath": "payments/OrderCreateForAuthorization", + "pageTitle": "payments/OrderCreateForAuthorization", + "title": "OrderCreateForAuthorization" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Order Create Using PayPal", + "slug": "order-create-using-paypal" }, "depth": 1, "children": [ @@ -1108,13 +1362,99 @@ 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 "foldPrefix": "^", "name": "PHP" }, - "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/CreatePaymentUsingSavedCard.php", - "projectPath": "payments/CreatePaymentUsingSavedCard.php", - "targetPath": "payments/CreatePaymentUsingSavedCard", - "pageTitle": "payments/CreatePaymentUsingSavedCard", - "title": "CreatePaymentUsingSavedCard" + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderCreateForCapture.php", + "projectPath": "payments/OrderCreateForCapture.php", + "targetPath": "payments/OrderCreateForCapture", + "pageTitle": "payments/OrderCreateForCapture", + "title": "OrderCreateForCapture" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Order Create Using PayPal", + "slug": "order-create-using-paypal" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Itemized information", + "slug": "itemized-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional payment details", + "slug": "additional-payment-details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Redirect urls", + "slug": "redirect-urls" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1126,13 +1466,99 @@ 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 "foldPrefix": "^", "name": "PHP" }, - "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/ExecutePayment.php", - "projectPath": "payments/ExecutePayment.php", - "targetPath": "payments/ExecutePayment", - "pageTitle": "payments/ExecutePayment", - "title": "ExecutePayment" + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderCreateForVoid.php", + "projectPath": "payments/OrderCreateForVoid.php", + "targetPath": "payments/OrderCreateForVoid", + "pageTitle": "payments/OrderCreateForVoid", + "title": "OrderCreateForVoid" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Order Create Using PayPal", + "slug": "order-create-using-paypal" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Itemized information", + "slug": "itemized-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional payment details", + "slug": "additional-payment-details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Redirect urls", + "slug": "redirect-urls" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1144,13 +1570,99 @@ 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 "foldPrefix": "^", "name": "PHP" }, - "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/GetAuthorization.php", - "projectPath": "payments/GetAuthorization.php", - "targetPath": "payments/GetAuthorization", - "pageTitle": "payments/GetAuthorization", - "title": "GetAuthorization" + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderCreateUsingPayPal.php", + "projectPath": "payments/OrderCreateUsingPayPal.php", + "targetPath": "payments/OrderCreateUsingPayPal", + "pageTitle": "payments/OrderCreateUsingPayPal", + "title": "OrderCreateUsingPayPal" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Order Create Using PayPal", + "slug": "order-create-using-paypal" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Itemized information", + "slug": "itemized-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional payment details", + "slug": "additional-payment-details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Redirect urls", + "slug": "redirect-urls" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1162,13 +1674,51 @@ 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 "foldPrefix": "^", "name": "PHP" }, - "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/GetCapture.php", - "projectPath": "payments/GetCapture.php", - "targetPath": "payments/GetCapture", - "pageTitle": "payments/GetCapture", - "title": "GetCapture" + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderDoVoid.php", + "projectPath": "payments/OrderDoVoid.php", + "targetPath": "payments/OrderDoVoid", + "pageTitle": "payments/OrderDoVoid", + "title": "OrderDoVoid" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Void Order Sample", + "slug": "void-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": "Void Order", + "slug": "void-order" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1180,31 +1730,35 @@ 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 "foldPrefix": "^", "name": "PHP" }, - "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/GetPayment.php", - "projectPath": "payments/GetPayment.php", - "targetPath": "payments/GetPayment", - "pageTitle": "payments/GetPayment", - "title": "GetPayment" + "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/OrderGet.php", + "projectPath": "payments/OrderGet.php", + "targetPath": "payments/OrderGet", + "pageTitle": "payments/OrderGet", + "title": "OrderGet" }, - "depth": 2 - }, { - "type": "file", - "data": { - "language": { - "nameMatchers": [{}, ".fbp"], - "pygmentsLexer": "php", - "singleLineComment": ["//"], - "ignorePrefix": "}", - "foldPrefix": "^", - "name": "PHP" - }, - "sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/payments/ListPayments.php", - "projectPath": "payments/ListPayments.php", - "targetPath": "payments/ListPayments", - "pageTitle": "payments/ListPayments", - "title": "ListPayments" - }, - "depth": 2 + "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 + } + ] + } + ] }, { "type": "file", "data": { @@ -1340,56 +1894,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": "payouts/CreateSinglePayout", "title": "CreateSinglePayout" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Create Single Synchronous Payout Sample", - "slug": "create-single-synchronous-payout-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "NOTE:", - "slug": "note" - }, - "depth": 3, - "children": [ - { - "type": "heading", - "data": { - "level": 4, - "title": "Batch Header Instance", - "slug": "batch-header-instance" - }, - "depth": 4 - }, { - "type": "heading", - "data": { - "level": 4, - "title": "Sender Item", - "slug": "sender-item" - }, - "depth": 4 - } - ] - }, { - "type": "heading", - "data": { - "level": 3, - "title": "Create Payout", - "slug": "create-payout" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1517,37 +2022,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": "vault/CreateCreditCard", "title": "CreateCreditCard" }, - "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": "Save card", - "slug": "save-card" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1637,37 +2112,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": "vault/UpdateCreditCard", "title": "UpdateCreditCard" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Update Credit Card Sample", - "slug": "update-credit-card-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Patch Object", - "slug": "patch-object" - }, - "depth": 3 - }, { - "type": "heading", - "data": { - "level": 3, - "title": "Another Patch Object", - "slug": "another-patch-object" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 } ] } diff --git a/sample/doc/billing/CreateBillingAgreementWithPayPal.html b/sample/doc/billing/CreateBillingAgreementWithPayPal.html index 1e07903..af586ee 100644 --- a/sample/doc/billing/CreateBillingAgreementWithPayPal.html +++ b/sample/doc/billing/CreateBillingAgreementWithPayPal.html @@ -47,7 +47,7 @@ Please note that the plan Id should be only set in this case.

$agreement->setShippingAddress($shippingAddress);

For Sample Purposes Only.

$request = clone $agreement;

Create Agreement

try {

Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.

$agreement = $agreement->create($apiContext);

Get redirect url

The API response provides the url that you must redirect the buyer to. Retrieve the url from the $agreement->getApprovalLink() -method

$approvalUrl = $agreement->getApprovalLink(); +method

$approvalUrl = $agreement->getApprovalLink(); } catch (Exception $ex) { ResultPrinter::printError("Created Billing Agreement.", "Agreement", null, $request, $ex); diff --git a/sample/doc/payments/ExecutePayment.html b/sample/doc/payments/ExecutePayment.html index ba7c7e5..02df941 100644 --- a/sample/doc/payments/ExecutePayment.html +++ b/sample/doc/payments/ExecutePayment.html @@ -19,15 +19,21 @@ CreatePaymentUsingPayPal.php

Execute the payment -(See bootstrap.php for more on ApiContext)

$result = $payment->execute($execution, $apiContext); + $execution->setPayerId($_GET['PayerID']); - ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); + try {

Execute the payment +(See bootstrap.php for more on ApiContext)

$result = $payment->execute($execution, $apiContext); - try { - $payment = Payment::get($paymentId, $apiContext); + ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); + + try { + $payment = Payment::get($paymentId, $apiContext); + } catch (Exception $ex) { + ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + exit(1); + } } catch (Exception $ex) { - ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + ResultPrinter::printError("Executed Payment", "Payment", null, null, $ex); exit(1); } @@ -38,4 +44,5 @@ when the user is redirected from paypal back to your site

else { ResultPrinter::printResult("User Cancelled the Approval", null); + exit; }
\ No newline at end of file diff --git a/sample/doc/payments/OrderAuthorize.html b/sample/doc/payments/OrderAuthorize.html new file mode 100644 index 0000000..a057bea --- /dev/null +++ b/sample/doc/payments/OrderAuthorize.html @@ -0,0 +1,37 @@ +payments/OrderAuthorize
payments/OrderAuthorize.php
<?php

Authorize Order Sample

+

To authorize an order payment, pass the orderId in the URI of a POST call. This begins the process of confirming that funds are available until it is time to complete the payment transaction. +API used: POST /v1/payments/orders//authorize

/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +use PayPal\Api\Order; +use PayPal\Api\Amount; +use PayPal\Api\Authorization;

Approval Status

+

Determine if the user approved the payment or not

if (isset($_GET['success']) && $_GET['success'] == 'true') {

Retrieve the order

+

OrderId could be retrieved by parsing the object inside related_resources.

$transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder();

Create Authorization Object

+

with Amount in it

$authorization = new Authorization(); + $authorization->setAmount(new Amount( + '{ + "total": "2.00", + "currency": "USD" + }' + )); + + try {

Authorize Order

+

Authorize the order by passing authorization object we created. +We will get a new authorization object back.

$result = $order->authorize($authorization, $apiContext); + ResultPrinter::printResult("Authorized Order", "Authorization", $result->getId(), $authorization, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Authorized Order", "Authorization", null, $authorization, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +}
\ No newline at end of file diff --git a/sample/doc/payments/OrderCapture.html b/sample/doc/payments/OrderCapture.html new file mode 100644 index 0000000..39f35a3 --- /dev/null +++ b/sample/doc/payments/OrderCapture.html @@ -0,0 +1,37 @@ +payments/OrderCapture
payments/OrderCapture.php
<?php

Capture Order Sample

+

To authorize an order payment, pass the orderId in the URI of a POST call. This begins the process of confirming that funds are available until it is time to complete the payment transaction. +API used: POST /v1/payments/orders//authorize

/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +use PayPal\Api\Capture; +use PayPal\Api\Amount;

Approval Status

+

Determine if the user approved the payment or not

if (isset($_GET['success']) && $_GET['success'] == 'true') {

Retrieve the order

+

OrderId could be retrieved by parsing the object inside related_resources.

$transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder();

Create Capture Object

+

with Amount in it

$capture = new Capture(); + $capture->setIsFinalCapture(true); + $capture->setAmount(new Amount( + '{ + "total": "2.00", + "currency": "USD" + }' + )); + + try {

Capture Order

+

Capture the order by passing capture object we created. +We will get a new capture object back.

$result = $order->capture($capture, $apiContext); + ResultPrinter::printResult("Captured Order", "Capture", $result->getId(), $capture, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Captured Order", "Capture", null, $capture, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +}
\ No newline at end of file diff --git a/sample/doc/payments/OrderCreateForAuthorization.html b/sample/doc/payments/OrderCreateForAuthorization.html new file mode 100644 index 0000000..81809fd --- /dev/null +++ b/sample/doc/payments/OrderCreateForAuthorization.html @@ -0,0 +1,77 @@ +payments/OrderCreateForAuthorization
payments/OrderCreateForAuthorization.php
<?php

Order Create Using PayPal

+

In a call to the /payment resource, provide the payment details. In the intent field, specify order, and set the payment_method to paypal. Creating an order is similar to creating a payment. +API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\RedirectUrls; +use PayPal\Api\Transaction;

Payer

+

A resource representing a Payer that funds a payment +For paypal account payments, set payment method +to 'paypal'.

$payer = new Payer(); +$payer->setPaymentMethod("paypal");

Itemized information

+

(Optional) Lets you specify item wise +information

$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2));

Additional payment details

+

Use this optional field to set additional +payment information such as tax, shipping +charges etc.

$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50);

Amount

+

Lets you specify a payment amount. +You can also specify additional details +such as shipping, tax.

$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details);

Transaction

+

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it.

$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Redirect urls

+

Set the urls that the buyer must be redirected to after +payment approval/ cancellation.

$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderAuthorize.php?success=true") + ->setCancelUrl("$baseUrl/OrderAuthorize.php?success=false");

Payment

+

A Payment Resource; create one using +the above types and intent set to 'order'

$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

+

Create a payment by calling the 'create' method +passing it a valid apiContext. +(See bootstrap.php for more on ApiContext) +The return object contains the state and the +url to which the buyer must be redirected to +for payment approval

try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +}

Get redirect url

+

The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $payment->getApprovalLink() +method

$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); + +return $payment;
\ No newline at end of file diff --git a/sample/doc/payments/OrderCreateForCapture.html b/sample/doc/payments/OrderCreateForCapture.html new file mode 100644 index 0000000..7ae56f2 --- /dev/null +++ b/sample/doc/payments/OrderCreateForCapture.html @@ -0,0 +1,77 @@ +payments/OrderCreateForCapture
payments/OrderCreateForCapture.php
<?php

Order Create Using PayPal

+

In a call to the /payment resource, provide the payment details. In the intent field, specify order, and set the payment_method to paypal. Creating an order is similar to creating a payment. +API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\RedirectUrls; +use PayPal\Api\Transaction;

Payer

+

A resource representing a Payer that funds a payment +For paypal account payments, set payment method +to 'paypal'.

$payer = new Payer(); +$payer->setPaymentMethod("paypal");

Itemized information

+

(Optional) Lets you specify item wise +information

$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2));

Additional payment details

+

Use this optional field to set additional +payment information such as tax, shipping +charges etc.

$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50);

Amount

+

Lets you specify a payment amount. +You can also specify additional details +such as shipping, tax.

$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details);

Transaction

+

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it.

$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Redirect urls

+

Set the urls that the buyer must be redirected to after +payment approval/ cancellation.

$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderCapture.php?success=true") + ->setCancelUrl("$baseUrl/OrderCapture.php?success=false");

Payment

+

A Payment Resource; create one using +the above types and intent set to 'order'

$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

+

Create a payment by calling the 'create' method +passing it a valid apiContext. +(See bootstrap.php for more on ApiContext) +The return object contains the state and the +url to which the buyer must be redirected to +for payment approval

try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +}

Get redirect url

+

The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $payment->getApprovalLink() +method

$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); + +return $payment;
\ No newline at end of file diff --git a/sample/doc/payments/OrderCreateForVoid.html b/sample/doc/payments/OrderCreateForVoid.html new file mode 100644 index 0000000..e4f341c --- /dev/null +++ b/sample/doc/payments/OrderCreateForVoid.html @@ -0,0 +1,77 @@ +payments/OrderCreateForVoid
payments/OrderCreateForVoid.php
<?php

Order Create Using PayPal

+

In a call to the /payment resource, provide the payment details. In the intent field, specify order, and set the payment_method to paypal. Creating an order is similar to creating a payment. +API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\RedirectUrls; +use PayPal\Api\Transaction;

Payer

+

A resource representing a Payer that funds a payment +For paypal account payments, set payment method +to 'paypal'.

$payer = new Payer(); +$payer->setPaymentMethod("paypal");

Itemized information

+

(Optional) Lets you specify item wise +information

$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2));

Additional payment details

+

Use this optional field to set additional +payment information such as tax, shipping +charges etc.

$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50);

Amount

+

Lets you specify a payment amount. +You can also specify additional details +such as shipping, tax.

$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details);

Transaction

+

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it.

$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Redirect urls

+

Set the urls that the buyer must be redirected to after +payment approval/ cancellation.

$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderDoVoid.php?success=true") + ->setCancelUrl("$baseUrl/OrderDoVoid.php?success=false");

Payment

+

A Payment Resource; create one using +the above types and intent set to 'order'

$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

+

Create a payment by calling the 'create' method +passing it a valid apiContext. +(See bootstrap.php for more on ApiContext) +The return object contains the state and the +url to which the buyer must be redirected to +for payment approval

try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +}

Get redirect url

+

The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $payment->getApprovalLink() +method

$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); + +return $payment;
\ No newline at end of file diff --git a/sample/doc/payments/OrderCreateUsingPayPal.html b/sample/doc/payments/OrderCreateUsingPayPal.html new file mode 100644 index 0000000..2ae7ada --- /dev/null +++ b/sample/doc/payments/OrderCreateUsingPayPal.html @@ -0,0 +1,77 @@ +payments/OrderCreateUsingPayPal
payments/OrderCreateUsingPayPal.php
<?php

Order Create Using PayPal

+

In a call to the /payment resource, provide the payment details. In the intent field, specify order, and set the payment_method to paypal. Creating an order is similar to creating a payment. +API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\RedirectUrls; +use PayPal\Api\Transaction;

Payer

+

A resource representing a Payer that funds a payment +For paypal account payments, set payment method +to 'paypal'.

$payer = new Payer(); +$payer->setPaymentMethod("paypal");

Itemized information

+

(Optional) Lets you specify item wise +information

$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2));

Additional payment details

+

Use this optional field to set additional +payment information such as tax, shipping +charges etc.

$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50);

Amount

+

Lets you specify a payment amount. +You can also specify additional details +such as shipping, tax.

$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details);

Transaction

+

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it.

$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid());

Redirect urls

+

Set the urls that the buyer must be redirected to after +payment approval/ cancellation.

$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderGet.php?success=true") + ->setCancelUrl("$baseUrl/OrderGet.php?success=false");

Payment

+

A Payment Resource; create one using +the above types and intent set to 'order'

$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

+

Create a payment by calling the 'create' method +passing it a valid apiContext. +(See bootstrap.php for more on ApiContext) +The return object contains the state and the +url to which the buyer must be redirected to +for payment approval

try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +}

Get redirect url

+

The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $payment->getApprovalLink() +method

$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment); + +return $payment;
\ No newline at end of file diff --git a/sample/doc/payments/OrderDoVoid.html b/sample/doc/payments/OrderDoVoid.html new file mode 100644 index 0000000..31877de --- /dev/null +++ b/sample/doc/payments/OrderDoVoid.html @@ -0,0 +1,29 @@ +payments/OrderDoVoid
payments/OrderDoVoid.php
<?php

Void Order Sample

+

Use this call to void an existing order. +Note: An order cannot be voided if payment has already been partially or fully captured. +API used: POST /v1/payments/orders//do-void

/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +use PayPal\Api\Capture; +use PayPal\Api\Amount;

Approval Status

+

Determine if the user approved the payment or not

if (isset($_GET['success']) && $_GET['success'] == 'true') {

Retrieve the order

+

OrderId could be retrieved by parsing the object inside related_resources.

$transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder(); + + try {

Void Order

+

Call void method on order object. You will get an Order Object back

$result = $order->void($apiContext); + ResultPrinter::printResult("Voided Order", "Order", $result->getId(), null, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Voided Order", "Order", null, null, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +}
\ No newline at end of file diff --git a/sample/doc/payments/OrderGet.html b/sample/doc/payments/OrderGet.html new file mode 100644 index 0000000..f5bb705 --- /dev/null +++ b/sample/doc/payments/OrderGet.html @@ -0,0 +1,26 @@ +payments/OrderGet
payments/OrderGet.php
<?php

Get Order Sample

+

Specify an order ID to get details about an order. +API used: GET /v1/payments/orders/

/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php';

Approval Status

+

Determine if the user approved the payment or not

if (isset($_GET['success']) && $_GET['success'] == 'true') { + + $transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder(); + + try { + $result = \PayPal\Api\Order::get($order->getId(), $apiContext); + ResultPrinter::printResult("Get Order", "Order", $result->getId(), null, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Get Order", "Order", null, null, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +}
\ No newline at end of file diff --git a/sample/index.php b/sample/index.php index 0ce66c0..5703a82 100644 --- a/sample/index.php +++ b/sample/index.php @@ -219,6 +219,7 @@ if (PHP_SAPI == 'cli') {
  • Payouts
  • Authorization and Capture
  • Sale
  • +
  • Order
  • Billing Plan & Agreements
  • Vault
  • Payment Experience
  • @@ -544,6 +545,130 @@ if (PHP_SAPI == 'cli') { +
    +
    +

    Order

    +
    + + +
    +

    setPayerId($_GET['PayerID']); - // Execute the payment - // (See bootstrap.php for more on `ApiContext`) - $result = $payment->execute($execution, $apiContext); - - ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); - try { - $payment = Payment::get($paymentId, $apiContext); + // Execute the payment + // (See bootstrap.php for more on `ApiContext`) + $result = $payment->execute($execution, $apiContext); + + ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); + + try { + $payment = Payment::get($paymentId, $apiContext); + } catch (Exception $ex) { + ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + exit(1); + } } catch (Exception $ex) { - ResultPrinter::printError("Get Payment", "Payment", null, null, $ex); + ResultPrinter::printError("Executed Payment", "Payment", null, null, $ex); exit(1); } @@ -53,4 +58,5 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') { } else { ResultPrinter::printResult("User Cancelled the Approval", null); + exit; } diff --git a/sample/payments/OrderAuthorize.php b/sample/payments/OrderAuthorize.php new file mode 100644 index 0000000..5cd0ad6 --- /dev/null +++ b/sample/payments/OrderAuthorize.php @@ -0,0 +1,51 @@ +/authorize + +/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +use PayPal\Api\Order; +use PayPal\Api\Amount; +use PayPal\Api\Authorization; + +// ### Approval Status +// Determine if the user approved the payment or not +if (isset($_GET['success']) && $_GET['success'] == 'true') { + + // ### Retrieve the order + // OrderId could be retrieved by parsing the object inside related_resources. + $transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder(); + + // ### Create Authorization Object + // with Amount in it + $authorization = new Authorization(); + $authorization->setAmount(new Amount( + '{ + "total": "2.00", + "currency": "USD" + }' + )); + + try { + // ### Authorize Order + // Authorize the order by passing authorization object we created. + // We will get a new authorization object back. + $result = $order->authorize($authorization, $apiContext); + ResultPrinter::printResult("Authorized Order", "Authorization", $result->getId(), $authorization, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Authorized Order", "Authorization", null, $authorization, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +} diff --git a/sample/payments/OrderCapture.php b/sample/payments/OrderCapture.php new file mode 100644 index 0000000..b274db6 --- /dev/null +++ b/sample/payments/OrderCapture.php @@ -0,0 +1,51 @@ +/authorize + +/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +use PayPal\Api\Capture; +use PayPal\Api\Amount; + +// ### Approval Status +// Determine if the user approved the payment or not +if (isset($_GET['success']) && $_GET['success'] == 'true') { + + // ### Retrieve the order + // OrderId could be retrieved by parsing the object inside related_resources. + $transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder(); + + // ### Create Capture Object + // with Amount in it + $capture = new Capture(); + $capture->setIsFinalCapture(true); + $capture->setAmount(new Amount( + '{ + "total": "2.00", + "currency": "USD" + }' + )); + + try { + // ### Capture Order + // Capture the order by passing capture object we created. + // We will get a new capture object back. + $result = $order->capture($capture, $apiContext); + ResultPrinter::printResult("Captured Order", "Capture", $result->getId(), $capture, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Captured Order", "Capture", null, $capture, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +} diff --git a/sample/payments/OrderCreateForAuthorization.php b/sample/payments/OrderCreateForAuthorization.php new file mode 100644 index 0000000..d6026b3 --- /dev/null +++ b/sample/payments/OrderCreateForAuthorization.php @@ -0,0 +1,112 @@ +setPaymentMethod("paypal"); + +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50); + +// ### Amount +// Lets you specify a payment amount. +// You can also specify additional details +// such as shipping, tax. +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); + +// ### Redirect urls +// Set the urls that the buyer must be redirected to after +// payment approval/ cancellation. +$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderAuthorize.php?success=true") + ->setCancelUrl("$baseUrl/OrderAuthorize.php?success=false"); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent set to 'order' +$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; + +// ### Create Payment +// Create a payment by calling the 'create' method +// passing it a valid apiContext. +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the state and the +// url to which the buyer must be redirected to +// for payment approval +try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +} + +// ### Get redirect url +// The API response provides the url that you must redirect +// the buyer to. Retrieve the url from the $payment->getApprovalLink() +// method +$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "$approvalUrl", $request, $payment); + +return $payment; diff --git a/sample/payments/OrderCreateForCapture.php b/sample/payments/OrderCreateForCapture.php new file mode 100644 index 0000000..4c40fef --- /dev/null +++ b/sample/payments/OrderCreateForCapture.php @@ -0,0 +1,112 @@ +setPaymentMethod("paypal"); + +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50); + +// ### Amount +// Lets you specify a payment amount. +// You can also specify additional details +// such as shipping, tax. +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); + +// ### Redirect urls +// Set the urls that the buyer must be redirected to after +// payment approval/ cancellation. +$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderCapture.php?success=true") + ->setCancelUrl("$baseUrl/OrderCapture.php?success=false"); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent set to 'order' +$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; + +// ### Create Payment +// Create a payment by calling the 'create' method +// passing it a valid apiContext. +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the state and the +// url to which the buyer must be redirected to +// for payment approval +try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +} + +// ### Get redirect url +// The API response provides the url that you must redirect +// the buyer to. Retrieve the url from the $payment->getApprovalLink() +// method +$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "$approvalUrl", $request, $payment); + +return $payment; diff --git a/sample/payments/OrderCreateForVoid.php b/sample/payments/OrderCreateForVoid.php new file mode 100644 index 0000000..6e44a94 --- /dev/null +++ b/sample/payments/OrderCreateForVoid.php @@ -0,0 +1,112 @@ +setPaymentMethod("paypal"); + +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50); + +// ### Amount +// Lets you specify a payment amount. +// You can also specify additional details +// such as shipping, tax. +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); + +// ### Redirect urls +// Set the urls that the buyer must be redirected to after +// payment approval/ cancellation. +$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderDoVoid.php?success=true") + ->setCancelUrl("$baseUrl/OrderDoVoid.php?success=false"); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent set to 'order' +$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; + +// ### Create Payment +// Create a payment by calling the 'create' method +// passing it a valid apiContext. +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the state and the +// url to which the buyer must be redirected to +// for payment approval +try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +} + +// ### Get redirect url +// The API response provides the url that you must redirect +// the buyer to. Retrieve the url from the $payment->getApprovalLink() +// method +$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "$approvalUrl", $request, $payment); + +return $payment; diff --git a/sample/payments/OrderCreateUsingPayPal.php b/sample/payments/OrderCreateUsingPayPal.php new file mode 100644 index 0000000..5f62b2b --- /dev/null +++ b/sample/payments/OrderCreateUsingPayPal.php @@ -0,0 +1,112 @@ +setPaymentMethod("paypal"); + +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice(7.5); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice(2); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping(1.2) + ->setTax(1.3) + ->setSubtotal(17.50); + +// ### Amount +// Lets you specify a payment amount. +// You can also specify additional details +// such as shipping, tax. +$amount = new Amount(); +$amount->setCurrency("USD") + ->setTotal(20) + ->setDetails($details); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. +$transaction = new Transaction(); +$transaction->setAmount($amount) + ->setItemList($itemList) + ->setDescription("Payment description") + ->setInvoiceNumber(uniqid()); + +// ### Redirect urls +// Set the urls that the buyer must be redirected to after +// payment approval/ cancellation. +$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturnUrl("$baseUrl/OrderGet.php?success=true") + ->setCancelUrl("$baseUrl/OrderGet.php?success=false"); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent set to 'order' +$payment = new Payment(); +$payment->setIntent("order") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + +// For Sample Purposes Only. +$request = clone $payment; + +// ### Create Payment +// Create a payment by calling the 'create' method +// passing it a valid apiContext. +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the state and the +// url to which the buyer must be redirected to +// for payment approval +try { + $payment->create($apiContext); +} catch (Exception $ex) { + ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); + exit(1); +} + +// ### Get redirect url +// The API response provides the url that you must redirect +// the buyer to. Retrieve the url from the $payment->getApprovalLink() +// method +$approvalUrl = $payment->getApprovalLink(); + +ResultPrinter::printResult("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", "$approvalUrl", $request, $payment); + +return $payment; diff --git a/sample/payments/OrderDoVoid.php b/sample/payments/OrderDoVoid.php new file mode 100644 index 0000000..b9064a8 --- /dev/null +++ b/sample/payments/OrderDoVoid.php @@ -0,0 +1,40 @@ +/do-void + +/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +use PayPal\Api\Capture; +use PayPal\Api\Amount; + +// ### Approval Status +// Determine if the user approved the payment or not +if (isset($_GET['success']) && $_GET['success'] == 'true') { + + // ### Retrieve the order + // OrderId could be retrieved by parsing the object inside related_resources. + $transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder(); + + try { + // ### Void Order + // Call void method on order object. You will get an Order Object back + $result = $order->void($apiContext); + ResultPrinter::printResult("Voided Order", "Order", $result->getId(), null, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Voided Order", "Order", null, null, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +} diff --git a/sample/payments/OrderGet.php b/sample/payments/OrderGet.php new file mode 100644 index 0000000..c9caa8c --- /dev/null +++ b/sample/payments/OrderGet.php @@ -0,0 +1,32 @@ + + +/** @var \PayPal\Api\Payment $payment */ +$payment = require __DIR__ . '/ExecutePayment.php'; + +// ### Approval Status +// Determine if the user approved the payment or not +if (isset($_GET['success']) && $_GET['success'] == 'true') { + + $transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $relatedResource = $relatedResources[0]; + $order = $relatedResource->getOrder(); + + try { + $result = \PayPal\Api\Order::get($order->getId(), $apiContext); + ResultPrinter::printResult("Get Order", "Order", $result->getId(), null, $result); + } catch (Exception $ex) { + ResultPrinter::printError("Get Order", "Order", null, null, $ex); + exit(1); + } + + return $result; + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); + exit; +}