Enabled Payout API Support

- Includes Unit and Functional Tests
- Includes Samples
This commit is contained in:
japatel
2015-01-02 16:41:36 -06:00
parent 9e7cb951a6
commit 6f13399e47
32 changed files with 4752 additions and 1165 deletions

View File

@@ -0,0 +1,101 @@
<?php
namespace PayPal\Test\Functional\Api;
use PayPal\Api\Patch;
use PayPal\Api\Payout;
use PayPal\Api\PayoutBatch;
use PayPal\Api\PayoutItem;
use PayPal\Common\PayPalModel;
use PayPal\Rest\ApiContext;
use PayPal\Rest\IResource;
use PayPal\Api\CreateProfileResponse;
use PayPal\Test\Functional\Setup;
use PayPal\Transport\PayPalRestCall;
use PayPal\Api\WebProfile;
/**
* Class Payouts
*
* @package PayPal\Test\Api
*/
class PayoutsFunctionalTest extends \PHPUnit_Framework_TestCase
{
public $operation;
public $response;
public $mockPayPalRestCall;
public static $batchId;
public function setUp()
{
$className = $this->getClassName();
$testName = $this->getName();
$operationString = file_get_contents(__DIR__ . "/../resources/$className/$testName.json");
$this->operation = json_decode($operationString, true);
$this->response = true;
if (array_key_exists('body', $this->operation['response'])) {
$this->response = json_encode($this->operation['response']['body']);
}
Setup::SetUpForFunctionalTests($this);
}
/**
* Returns just the classname of the test you are executing. It removes the namespaces.
* @return string
*/
public function getClassName()
{
return join('', array_slice(explode('\\', get_class($this)), -1));
}
public function testCreate()
{
$request = $this->operation['request']['body'];
$obj = new Payout($request);
if (Setup::$mode != 'mock') {
$obj->getSenderBatchHeader()->setSenderBatchId(uniqid());
}
PayoutsFunctionalTest::$batchId = $obj->getSenderBatchHeader()->getSenderBatchId();
$params = array('sync_mode' => 'true');
$result = $obj->create($params, null, $this->mockPayPalRestCall);
$this->assertNotNull($result);
$this->assertEquals(PayoutsFunctionalTest::$batchId, $result->getBatchHeader()->getSenderBatchHeader()->getSenderBatchId());
return $result;
}
/**
* @depends testCreate
* @param $payoutBatch PayoutBatch
* @return PayoutBatch
*/
public function testGet($payoutBatch)
{
$result = Payout::get($payoutBatch->getBatchHeader()->getPayoutBatchId(), null, $this->mockPayPalRestCall);
$this->assertNotNull($result);
$this->assertNotNull($result->getBatchHeader()->getBatchStatus());
$this->assertEquals(PayoutsFunctionalTest::$batchId, $result->getBatchHeader()->getSenderBatchHeader()->getSenderBatchId());
return $result;
}
/**
* @depends testCreate
* @param $payoutBatch PayoutBatch
* @return PayoutBatch
*/
public function testGetItem($payoutBatch)
{
$item = $payoutBatch->getItems()[0];
$result = PayoutItem::get($item->getPayoutItemId(), null, $this->mockPayPalRestCall);
$this->assertNotNull($result);
$this->assertEquals($item->getPayoutItemId(), $result->getPayoutItemId());
$this->assertEquals($item->getPayoutBatchId(), $result->getPayoutBatchId());
$this->assertEquals($item->getTransactionId(), $result->getTransactionId());
$this->assertEquals($item->getPayoutItemFee(), $result->getPayoutItemFee());
}
}

View File

@@ -3,6 +3,7 @@
namespace PayPal\Test\Functional;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Core\PayPalConfigManager;
use PayPal\Core\PayPalCredentialManager;
use PayPal\Rest\ApiContext;
@@ -16,20 +17,14 @@ class Setup
$context = new ApiContext();
$context->setConfig(array(
'mode' => 'sandbox',
'acct1.ClientId' => 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS',
'acct1.ClientSecret' => 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE',
'validation.level' => 'warning'
));
PayPalCredentialManager::getInstance()->setCredentialObject(
new OAuthTokenCredential(
"AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS",
"EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL"
)
);
PayPalCredentialManager::getInstance()->setCredentialObject(PayPalCredentialManager::getInstance()->getCredentialObject('acct1'));
self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
if (self::$mode != 'sandbox') {

View File

@@ -0,0 +1,106 @@
{
"description" : "Sender POSTs a batch with 1 payout request. This example is for sync_mode=true. This means an immediate response. For sync_mode=false, the output will be run in back ground and the repsonse will be different.",
"title" : "POST batch sample",
"runnable" : true,
"operationId" : "payouts",
"user" : {
"scopes" : [ ]
},
"credentials" : {
"oauth": {
"path" : "/v1/oauth/token",
"clientId":"",
"clientSecret":""
}
},
"request":{
"path":"v1/payments/payouts?sync_mode=true",
"method":"POST",
"headers": {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
},
"body":{
"sender_batch_header":{
"sender_batch_id":"2014021801",
"email_subject":"You have a Payout!"
},
"items":[
{
"recipient_type":"EMAIL",
"amount":{
"value":"1.0",
"currency":"USD"
},
"note":"Thanks for your patronage!",
"sender_item_id":"2014031400023",
"receiver":"shirt-supplier-one@mail.com"
}
]
}
},
"response" : {
"status" : "201 OK",
"headers" : {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
},
"body" : {
"batch_header": {
"payout_batch_id": "CDZEC5MJ8R5HY",
"batch_status": "SUCCESS",
"time_created": "2014-46-14T06:46:22Z",
"time_completed": "2014-46-14T06:46:23Z",
"sender_batch_header": {
"sender_batch_id":"2014021801",
"email_subject": "You have a Payout!"
},
"amount": {
"currency": "USD",
"value": "1.0"
},
"fees": {
"currency": "USD",
"value": "0.02"
}
},
"items": [
{
"payout_item_id": "VHBFGN95AWV82",
"transaction_id": "0728664497487461D",
"transaction_status": "SUCCESS",
"payout_item_fee": {
"currency": "USD",
"value": "0.02"
},
"payout_batch_id": "CDZEC5MJ8R5HY",
"payout_item": {
"amount": {
"currency": "USD",
"value": "1.0"
},
"note": "Thanks for your patronage!",
"receiver": "anybody01@gmail.com",
"recipient_type": "EMAIL",
"sender_item_id": "201403140001"
},
"time_processed": "2014-46-14T06:46:23Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payouts-item/VHBFGN95AWV82",
"rel": "item",
"method": "GET"
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payouts/CDZEC5MJ8R5HY",
"rel": "self",
"method": "GET"
}
]
}
}
}

View File

@@ -0,0 +1,223 @@
{
"description" : "GET of a batch with multiple items.",
"title" : "GET batch with multiple items",
"runnable" : true,
"operationId" : "payouts.get",
"user" : {
"scopes" : [ ]
},
"credentials" : {
"oauth": {
"path" : "/v1/oauth/token",
"clientId":"",
"clientSecret":""
},
"login" : { },
"openIdConnect" : { }
},
"request" : {
"path" : "v1/payments/payouts/12345678",
"method" : "GET",
"headers" : {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
},
"body":{
}
},
"response" : {
"status" : "200 OK",
"headers" : {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
},
"body":{
"batch_header":{
"payout_batch_id":"12345678",
"batch_status":"PROCESSING",
"sender_batch_id":"2014021801123",
"time_created":"2014-01-27T10:17:00Z",
"time_completed":"2014-01-27T11:17:39.00Z",
"sender_batch_header":{
"sender_batch_id":"2014021801",
"email_subject":"You have a Payout!"
},
"amount":{
"value":"435.85",
"currency":"USD"
},
"fees":{
"value":"5.84",
"currency":"USD"
}
},
"items":[
{
"payout_item_id":"452176",
"transaction_id":"434176",
"transaction_status":"SUCCESS",
"payout_batch_id":"12345678",
"sender_batch_id":"2014021887",
"payout_item_fee":{
"currency":"USD",
"value":"1.00"
},
"payout_item":{
"recipient_type":"EMAIL",
"amount":{
"value":"65.24",
"currency":"EUR"
},
"note":"Thanks for your patronage!",
"receiver":"anybody77@gmail.com",
"payouts_item_id":"1421388",
"sender_item_id":"14Feb_978"
},
"time_created":"2014-01-27T10:17:00:00Z",
"time_processed":"2014-01-27T10:18:32Z"
},
{
"payout_item_id":"452123",
"transaction_id":"434123",
"transaction_status":"SUCCESS",
"payout_batch_id":"12345678",
"sender_batch_id":"2014021802",
"payout_item_fee":{
"currency":"USD",
"value":"1.00"
},
"payout_item":{
"recipient_type":"EMAIL",
"amount":{
"value":"59.87",
"currency":"EUR"
},
"note":"Thanks for your patronage!",
"receiver":"anybody34@gmail.com",
"payouts_item_id":"1421345",
"sender_item_id":"14Feb_321"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:18:15Z"
},
{
"payout_item_id":"452323",
"transaction_id":"434543",
"transaction_status":"SUCCESS",
"payout_batch_id":"12345678",
"sender_batch_id":"2014021802",
"payout_item_fee":{
"currency":"USD",
"value":"1.00"
},
"payout_item":{
"recipient_type":"EMAIL",
"amount":{
"value":"59.87",
"currency":"EUR"
},
"note":"Thanks for your patronage!",
"receiver":"anybody03@gmail.com",
"payouts_item_id":"1421355",
"sender_item_id":"14Feb_239"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:17:15Z"
},
{
"payout_item_id":"452350",
"transaction_id":"434543",
"transaction_status":"SUCCESS",
"payout_batch_id":"12345678",
"sender_batch_id":"2014021801",
"payout_item_fee":{
"currency":"USD",
"value":"0.75"
},
"payout_item":{
"recipient_type":"EMAIL",
"amount":{
"value":"19.87",
"currency":"USD"
},
"note":"Thanks for your patronage!",
"receiver":"anybody02@gmail.com",
"payouts_item_id":"1421332",
"sender_item_id":"14Feb_235"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:17:25Z"
},
{
"payout_item_id":"452345",
"transaction_id":"4345",
"transaction_status":"SUCCESS",
"payout_batch_id":"12345678",
"sender_batch_id":"2014021801",
"payout_item_fee":{
"currency":"USD",
"value":"0.75"
},
"payout_item":{
"recipient_type":"EMAIL",
"amount":{
"value":"9.87",
"currency":"USD"
},
"note":"Thanks for your patronage!",
"receiver":"anybody01@gmail.com",
"payouts_item_id":"1421342",
"sender_item_id":"14Feb_234"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:17:37Z"
},
{
"payout_item_id":"4782902",
"transaction_id":"6456456",
"transaction_status":"SUCCESS",
"payout_item_fee":{
"currency":"USD",
"value":"2.35"
},
"payout_batch_id":"12345678",
"sender_batch_id":"2014021801",
"payout_item":{
"recipient_type":"PHONE",
"amount":{
"value":"112.34",
"currency":"EUR"
},
"note":"Thanks for your support!",
"receiver":"91-734-234-1234",
"payouts_item_id":"1421343",
"sender_item_id":"14Feb_235"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:17:52Z"
},
{
"payout_item_id":"4782902",
"transaction_id":"",
"transaction_status":"PROCESSING",
"payout_batch_id":"12345678",
"sender_batch_id":"2014021801",
"payout_item":{
"recipient_type":"PHONE",
"amount":{
"value":"5.32",
"currency":"USD"
},
"note":"Thanks for your patronage!",
"receiver":"408X234-1234",
"payouts_item_id":"1421344",
"sender_item_id":"14Feb_235"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:17:41Z"
}
]
}
}
}

View File

@@ -0,0 +1,66 @@
{
"description" : "Sender needs status of one item.",
"title" : "GET item sample",
"runnable" : true,
"operationId" : "payouts.item",
"user" : {
"scopes" : [ ]
},
"credentials" : {
"oauth": {
"path" : "/v1/oauth/token",
"clientId":"",
"clientSecret":""
}
},
"request" : {
"path" : "v1/payments/payouts-item/452345",
"method" : "GET",
"headers" : {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
},
"body" : {}
},
"response" : {
"status" : "200 OK",
"headers" : {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
},
"body" : {
"items":[
{
"payout_item_id":"1421342",
"transaction_id":"4345",
"transaction_status":"SUCCESS",
"payout_item_fee":{"currency":"USD","value":"0.35"},
"payout_batch_id":"20140724",
"sender_batch_id":"2014021801",
"payout_item":{
"recipient_type":"EMAIL",
"amount":{ "value":"9.87", "currency":"USD"},
"note":"Thanks for your patronage!",
"receiver":"anybody01@gmail.com",
"payouts_item_id":"1421342",
"sender_item_id":"14Feb_234"
},
"time_created":"2014-01-27T10:17:00Z",
"time_processed":"2014-01-27T10:17:41Z",
"links": [
{
"rel": "self",
"href": "payouts-batch/{payout_batch_id}",
"method": "GET"
},
{
"rel": "self",
"href": "payouts-item/{payout_item_id}",
"method": "GET"
}
]
}
]
}
}
}