Order API Support

- Added Order API Support
- Updated Sample Code to demonstrate
- Updated Sample Docs
- Fixes #237
This commit is contained in:
japatel
2015-02-04 15:54:30 -06:00
parent 217a54f0a6
commit 47cd78172c
22 changed files with 2045 additions and 306 deletions

View File

@@ -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;
}
}