added transaction fee support to sale class

This commit is contained in:
Chaitanya Kuber
2015-02-03 12:19:34 +11:00
parent ac69aa65ed
commit 58be8bd5d3
4 changed files with 164 additions and 57 deletions

View File

@@ -2,9 +2,9 @@
namespace PayPal\Api; namespace PayPal\Api;
use PayPal\Api\Refund;
use PayPal\Common\PayPalResourceModel; use PayPal\Common\PayPalResourceModel;
use PayPal\Rest\ApiContext; use PayPal\Rest\ApiContext;
use PayPal\Api\Refund;
use PayPal\Transport\PayPalRestCall; use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator; use PayPal\Validation\ArgumentValidator;
@@ -13,7 +13,6 @@ use PayPal\Validation\ArgumentValidator;
* *
* A sale transaction. * A sale transaction.
* *
* @package PayPal\Api
* *
* @property string id * @property string id
* @property string create_time * @property string create_time
@@ -27,15 +26,31 @@ use PayPal\Validation\ArgumentValidator;
* @property string protection_eligibility_type * @property string protection_eligibility_type
* @property string clearing_time * @property string clearing_time
* @property string parent_payment * @property string parent_payment
* @property \PayPal\Api\TransactionFee $transactionFee
* @package PayPal\Api
*/ */
class Sale extends PayPalResourceModel class Sale extends PayPalResourceModel
{ {
public function setTransactionFee(\PayPal\Api\TransactionFee $transactionFee)
{
$this->transactionFee = $transactionFee;
return $this;
}
/**
* @return \PayPal\Api\TransactionFee
*/
public function getTransactionFee()
{
return $this->transactionFee;
}
/** /**
* Identifier of the authorization transaction. * Identifier of the authorization transaction.
* *
* *
* @param string $id
* *
* @param string $id
* @return $this * @return $this
*/ */
public function setId($id) public function setId($id)
@@ -58,8 +73,8 @@ class Sale extends PayPalResourceModel
* Time the resource was created. * Time the resource was created.
* *
* *
* @param string $create_time
* *
* @param string $create_time
* @return $this * @return $this
*/ */
public function setCreateTime($create_time) public function setCreateTime($create_time)
@@ -82,8 +97,8 @@ class Sale extends PayPalResourceModel
* Time the resource was last updated. * Time the resource was last updated.
* *
* *
* @param string $update_time
* *
* @param string $update_time
* @return $this * @return $this
*/ */
public function setUpdateTime($update_time) public function setUpdateTime($update_time)
@@ -106,8 +121,8 @@ class Sale extends PayPalResourceModel
* Amount being collected. * Amount being collected.
* *
* *
* @param \PayPal\Api\Amount $amount
* *
* @param \PayPal\Api\Amount $amount
* @return $this * @return $this
*/ */
public function setAmount($amount) public function setAmount($amount)
@@ -130,8 +145,8 @@ class Sale extends PayPalResourceModel
* specifies payment mode of the transaction * specifies payment mode of the transaction
* Valid Values: ["INSTANT_TRANSFER", "MANUAL_BANK_TRANSFER", "DELAYED_TRANSFER", "ECHECK"] * Valid Values: ["INSTANT_TRANSFER", "MANUAL_BANK_TRANSFER", "DELAYED_TRANSFER", "ECHECK"]
* *
* @param string $payment_mode
* *
* @param string $payment_mode
* @return $this * @return $this
*/ */
public function setPaymentMode($payment_mode) public function setPaymentMode($payment_mode)
@@ -154,8 +169,8 @@ class Sale extends PayPalResourceModel
* Reason of Pending transaction. * Reason of Pending transaction.
* *
* *
* @param string $pending_reason
* *
* @param string $pending_reason
* @return $this * @return $this
*/ */
public function setPendingReason($pending_reason) public function setPendingReason($pending_reason)
@@ -178,8 +193,8 @@ class Sale extends PayPalResourceModel
* State of the sale transaction. * State of the sale transaction.
* Valid Values: ["pending", "completed", "refunded", "partially_refunded"] * Valid Values: ["pending", "completed", "refunded", "partially_refunded"]
* *
* @param string $state
* *
* @param string $state
* @return $this * @return $this
*/ */
public function setState($state) public function setState($state)
@@ -202,8 +217,8 @@ class Sale extends PayPalResourceModel
* Reason code for the transaction state being Pending or Reversed. * 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"] * 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"]
* *
* @param string $reason_code
* *
* @param string $reason_code
* @return $this * @return $this
*/ */
public function setReasonCode($reason_code) public function setReasonCode($reason_code)
@@ -226,8 +241,8 @@ class Sale extends PayPalResourceModel
* Protection Eligibility of the Payer * Protection Eligibility of the Payer
* Valid Values: ["ELIGIBLE", "PARTIALLY_ELIGIBLE", "INELIGIBLE"] * Valid Values: ["ELIGIBLE", "PARTIALLY_ELIGIBLE", "INELIGIBLE"]
* *
* @param string $protection_eligibility
* *
* @param string $protection_eligibility
* @return $this * @return $this
*/ */
public function setProtectionEligibility($protection_eligibility) public function setProtectionEligibility($protection_eligibility)
@@ -250,8 +265,8 @@ class Sale extends PayPalResourceModel
* Protection Eligibility Type of the Payer * 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
* *
* @param string $protection_eligibility_type
* @return $this * @return $this
*/ */
public function setProtectionEligibilityType($protection_eligibility_type) public function setProtectionEligibilityType($protection_eligibility_type)
@@ -274,8 +289,8 @@ class Sale extends PayPalResourceModel
* Expected clearing time for eCheck Transactions * Expected clearing time for eCheck Transactions
* *
* *
* @param string $clearing_time
* *
* @param string $clearing_time
* @return $this * @return $this
*/ */
public function setClearingTime($clearing_time) public function setClearingTime($clearing_time)
@@ -298,8 +313,8 @@ class Sale extends PayPalResourceModel
* ID of the Payment resource that this transaction is based on. * ID of the Payment resource that this transaction is based on.
* *
* *
* @param string $parent_payment
* *
* @param string $parent_payment
* @return $this * @return $this
*/ */
public function setParentPayment($parent_payment) public function setParentPayment($parent_payment)

View File

@@ -0,0 +1,70 @@
<?php
namespace PayPal\Api;
use PayPal\Common\PayPalModel;
use PayPal\Converter\FormatConverter;
use PayPal\Validation\NumericValidator;
/**
* Class TranactionFee
*
* Let's you specify details of the transaction fee.
*
* @package PayPal\Api
*
* @property string currency
* @property string value
*/
class TransactionFee extends PayPalModel
{
/**
* 3 letter currency code
*
*
* @param string $currency
*
* @return $this
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* 3 letter currency code
*
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* Total amount charged from the Payer account (or card) to Payee. In case of a refund, this is the refunded amount to the original Payer from Payee account.
*
*
* @param string|double $value
*
* @return $this
*/
public function setValue($value)
{
NumericValidator::validate($value, "value");
$value = FormatConverter::formatToPrice($value, $this->getCurrency());
$this->value = $value;
return $this;
}
/**
* Value amount charged from the Payer account (or card) to Payee. In case of a refund, this is the refunded amount to the original Payer from Payee account.
*
* @return string
*/
public function getValue()
{
return $this->value;
}
}

View File

@@ -1,19 +1,16 @@
<?php <?php
namespace PayPal\Test\Api; namespace PayPal\Test\Api;
use PayPal\Api\Refund;
use PayPal\Api\Sale; use PayPal\Api\Sale;
use PayPal\Test\Constants;
use PayPal\Test\Api\AmountTest; use PayPal\Test\Api\AmountTest;
use PayPal\Test\Api\PaymentTest;
use PayPal\Test\Api\LinksTest;
use PayPal\Exception\PayPalConnectionException;
class SaleTest extends \PHPUnit_Framework_TestCase class SaleTest extends \PHPUnit_Framework_TestCase
{ {
/**
/** @var Sale */ * @var Sale
*/
private $sale; private $sale;
private $tFee;
public static $captureId = "CAP-123"; public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z"; public static $createTime = "2013-02-28T00:00:00Z";
@@ -21,7 +18,7 @@ class SaleTest extends \PHPUnit_Framework_TestCase
public static $parentPayment = "PAY-123"; public static $parentPayment = "PAY-123";
public static $state = "Created"; public static $state = "Created";
public static function createSale() private function createSale()
{ {
$sale = new Sale(); $sale = new Sale();
$sale->setAmount(AmountTest::createAmount()); $sale->setAmount(AmountTest::createAmount());
@@ -29,12 +26,18 @@ class SaleTest extends \PHPUnit_Framework_TestCase
$sale->setId(self::$id); $sale->setId(self::$id);
$sale->setParentPayment(self::$parentPayment); $sale->setParentPayment(self::$parentPayment);
$sale->setState(self::$state); $sale->setState(self::$state);
$this->tFee = new \PayPal\Api\TransactionFee();
$this->tFee->setCurrency('AUD');
$this->tFee->setValue('0.10');
$sale->setTransactionFee($this->tFee);
return $sale; return $sale;
} }
public function setup() public function setup()
{ {
$this->sale = self::createSale(); $this->sale = $this->createSale();
} }
public function testGetterSetter() public function testGetterSetter()
@@ -44,6 +47,7 @@ class SaleTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(self::$parentPayment, $this->sale->getParentPayment()); $this->assertEquals(self::$parentPayment, $this->sale->getParentPayment());
$this->assertEquals(self::$state, $this->sale->getState()); $this->assertEquals(self::$state, $this->sale->getState());
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency()); $this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
$this->assertEquals($this->tFee, $this->sale->getTransactionFee());
} }
public function testSerializeDeserialize() public function testSerializeDeserialize()

View File

@@ -0,0 +1,18 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\TransactionFee;
class TransactionFeeTest extends \PHPUnit_Framework_TestCase
{
public function testGetterSetter()
{
$tfee = new TransactionFee();
$tfee->setCurrency('AUD');
$this->assertEquals('AUD', $tfee->getCurrency());
$tfee->setValue('0.10');
$this->assertEquals('0.10', $tfee->getValue());
}
}