recreate project
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
// # Cancel Payout Item Status Sample
|
||||
//
|
||||
// Use this call to cancel an existing, unclaimed transaction. If an unclaimed item is not claimed within 30 days, the funds will be automatically returned to the sender. This call can be used to cancel the unclaimed item prior to the automatic 30-day return.
|
||||
// https://developer.paypal.com/docs/api/#cancel-an-unclaimed-payout-item
|
||||
// API used: POST /v1/payments/payouts-item/<Payout-Item-Id>/cancel
|
||||
|
||||
/** @var \PayPal\Api\PayoutBatch $payoutBatch */
|
||||
$payoutBatch = require 'CreateSinglePayout.php';
|
||||
// ## Payout Item ID
|
||||
// You can replace this with your Payout Batch Id on already created Payout.
|
||||
$payoutItems = $payoutBatch->getItems();
|
||||
$payoutItem = $payoutItems[0];
|
||||
$payoutItemId = $payoutItem->getPayoutItemId();
|
||||
|
||||
$output = null;
|
||||
// ### Cancel Payout Item
|
||||
// Check if Payout Item is UNCLAIMED, and if so, cancel it.
|
||||
try {
|
||||
if ($payoutItem->getTransactionStatus() == 'UNCLAIMED') {
|
||||
// Cancel the Payout Item
|
||||
$output = \PayPal\Api\PayoutItem::cancel($payoutItemId, $apiContext);
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Cancel Unclaimed Payout Item", "PayoutItem", $output->getPayoutItemId(), null, $output);
|
||||
} else {
|
||||
// The item transaction status is not unclaimed. You can only cancel an unclaimed transaction.
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Cancel Unclaimed Payout Item", "PayoutItem", null, $payoutItemId, new Exception("Payout Item Status is not UNCLAIMED"));
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Cancel Unclaimed Payout Item", "PayoutItem", null, $payoutItemId, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return $output;
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
// # Create Bulk Payout Sample
|
||||
//
|
||||
// This sample code demonstrate how you can create a synchronous payout sample, as documented here at:
|
||||
// https://developer.paypal.com/docs/integration/direct/create-batch-payout/
|
||||
// API used: /v1/payments/payouts
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
// Create a new instance of Payout object
|
||||
$payouts = new \PayPal\Api\Payout();
|
||||
|
||||
// This is how our body should look like:
|
||||
/*
|
||||
*{
|
||||
"sender_batch_header": {
|
||||
"sender_batch_id": "random_uniq_id",
|
||||
"email_subject": "You have a payment"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"recipient_type": "EMAIL",
|
||||
"amount": {
|
||||
"value": 0.99,
|
||||
"currency": "USD"
|
||||
},
|
||||
"receiver": "shirt-supplier-one@mail.com",
|
||||
"note": "Thank you.",
|
||||
"sender_item_id": "item_1"
|
||||
},
|
||||
{
|
||||
"recipient_type": "EMAIL",
|
||||
"amount": {
|
||||
"value": 0.90,
|
||||
"currency": "USD"
|
||||
},
|
||||
"receiver": "shirt-supplier-two@mail.com",
|
||||
"note": "Thank you.",
|
||||
"sender_item_id": "item_2"
|
||||
},
|
||||
{
|
||||
"recipient_type": "EMAIL",
|
||||
"amount": {
|
||||
"value": 2.00,
|
||||
"currency": "USD"
|
||||
},
|
||||
"receiver": "shirt-supplier-three@mail.com",
|
||||
"note": "Thank you.",
|
||||
"sender_item_id": "item_3"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
$senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
|
||||
// ### NOTE:
|
||||
// You can prevent duplicate batches from being processed. If you specify a `sender_batch_id` that was used in the last 30 days, the batch will not be processed. For items, you can specify a `sender_item_id`. If the value for the `sender_item_id` is a duplicate of a payout item that was processed in the last 30 days, the item will not be processed.
|
||||
|
||||
// #### Batch Header Instance
|
||||
$senderBatchHeader->setSenderBatchId(uniqid())
|
||||
->setEmailSubject("You have a payment");
|
||||
|
||||
// #### Sender Item
|
||||
// Please note that if you are using single payout with sync mode, you can only pass one Item in the request
|
||||
$senderItem1 = new \PayPal\Api\PayoutItem();
|
||||
$senderItem1->setRecipientType('Email')
|
||||
->setNote('Thanks you.')
|
||||
->setReceiver('shirt-supplier-one@gmail.com')
|
||||
->setSenderItemId("item_1" . uniqid())
|
||||
->setAmount(new \PayPal\Api\Currency('{
|
||||
"value":"0.99",
|
||||
"currency":"USD"
|
||||
}'));
|
||||
|
||||
// #### Sender Item 2
|
||||
// There are many different ways of assigning values in PayPal SDK. Here is another way where you could directly inject json string.
|
||||
$senderItem2 = new \PayPal\Api\PayoutItem(
|
||||
'{
|
||||
"recipient_type": "EMAIL",
|
||||
"amount": {
|
||||
"value": 0.90,
|
||||
"currency": "USD"
|
||||
},
|
||||
"receiver": "shirt-supplier-two@mail.com",
|
||||
"note": "Thank you.",
|
||||
"sender_item_id": "item_2"
|
||||
}'
|
||||
);
|
||||
|
||||
// #### Sender Item 3
|
||||
// One more way of assigning values in constructor when creating instance of PayPalModel object. Injecting array.
|
||||
$senderItem3 = new \PayPal\Api\PayoutItem(
|
||||
array(
|
||||
"recipient_type" => "EMAIL",
|
||||
"receiver" => "shirt-supplier-three@mail.com",
|
||||
"note" => "Thank you.",
|
||||
"sender_item_id" => uniqid(),
|
||||
"amount" => array(
|
||||
"value" => "0.90",
|
||||
"currency" => "USD"
|
||||
)
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$payouts->setSenderBatchHeader($senderBatchHeader)
|
||||
->addItem($senderItem1)->addItem($senderItem2)->addItem($senderItem3);
|
||||
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payouts;
|
||||
|
||||
// ### Create Payout
|
||||
try {
|
||||
$output = $payouts->create(null, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Created Batch Payout", "Payout", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Created Batch Payout", "Payout", $output->getBatchHeader()->getPayoutBatchId(), $request, $output);
|
||||
|
||||
return $output;
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
// # Create Single Synchronous Payout Sample
|
||||
//
|
||||
// This sample code demonstrate how you can create a synchronous payout sample, as documented here at:
|
||||
// https://developer.paypal.com/docs/integration/direct/create-single-payout/
|
||||
// API used: /v1/payments/payouts?sync_mode=true
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
// Create a new instance of Payout object
|
||||
$payouts = new \PayPal\Api\Payout();
|
||||
|
||||
// This is how our body should look like:
|
||||
/*
|
||||
* {
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
$senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
|
||||
// ### NOTE:
|
||||
// You can prevent duplicate batches from being processed. If you specify a `sender_batch_id` that was used in the last 30 days, the batch will not be processed. For items, you can specify a `sender_item_id`. If the value for the `sender_item_id` is a duplicate of a payout item that was processed in the last 30 days, the item will not be processed.
|
||||
|
||||
// #### Batch Header Instance
|
||||
$senderBatchHeader->setSenderBatchId(uniqid())
|
||||
->setEmailSubject("You have a Payout!");
|
||||
|
||||
// #### Sender Item
|
||||
// Please note that if you are using single payout with sync mode, you can only pass one Item in the request
|
||||
$senderItem = new \PayPal\Api\PayoutItem();
|
||||
$senderItem->setRecipientType('Email')
|
||||
->setNote('Thanks for your patronage!')
|
||||
->setReceiver('shirt-supplier-one@gmail.com')
|
||||
->setSenderItemId("2014031400023")
|
||||
->setAmount(new \PayPal\Api\Currency('{
|
||||
"value":"1.0",
|
||||
"currency":"USD"
|
||||
}'));
|
||||
|
||||
$payouts->setSenderBatchHeader($senderBatchHeader)
|
||||
->addItem($senderItem);
|
||||
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payouts;
|
||||
|
||||
// ### Create Payout
|
||||
try {
|
||||
$output = $payouts->createSynchronous($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Created Single Synchronous Payout", "Payout", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Created Single Synchronous Payout", "Payout", $output->getBatchHeader()->getPayoutBatchId(), $request, $output);
|
||||
|
||||
return $output;
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// # Get Payout Batch Status Sample
|
||||
//
|
||||
// This sample code demonstrate how you can get the batch payout status of a created batch payout, as documented here at:
|
||||
// https://developer.paypal.com/docs/api/#get-the-status-of-a-batch-payout
|
||||
// API used: GET /v1/payments/payouts/<Payout-Batch-Id>
|
||||
|
||||
/** @var \PayPal\Api\PayoutBatch $payoutBatch */
|
||||
$payoutBatch = require 'CreateBatchPayout.php';
|
||||
// ## Payout Batch ID
|
||||
// You can replace this with your Payout Batch Id on already created Payout.
|
||||
$payoutBatchId = $payoutBatch->getBatchHeader()->getPayoutBatchId();
|
||||
|
||||
// ### Get Payout Batch Status
|
||||
try {
|
||||
$output = \PayPal\Api\Payout::get($payoutBatchId, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Payout Batch Status", "PayoutBatch", null, $payoutBatchId, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Payout Batch Status", "PayoutBatch", $output->getBatchHeader()->getPayoutBatchId(), null, $output);
|
||||
|
||||
return $output;
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// # Get Payout Item Status Sample
|
||||
//
|
||||
// Use this call to get data about a payout item, including the status, without retrieving an entire batch. You can get the status of an individual payout item in a batch in order to review the current status of a previously-unclaimed, or pending, payout item.
|
||||
// https://developer.paypal.com/docs/api/#get-the-status-of-a-payout-item
|
||||
// API used: GET /v1/payments/payouts-item/<Payout-Item-Id>
|
||||
|
||||
/** @var \PayPal\Api\PayoutBatch $payoutBatch */
|
||||
$payoutBatch = require 'GetPayoutBatchStatus.php';
|
||||
// ## Payout Item ID
|
||||
// You can replace this with your Payout Batch Id on already created Payout.
|
||||
$payoutItems = $payoutBatch->getItems();
|
||||
$payoutItem = $payoutItems[0];
|
||||
$payoutItemId = $payoutItem->getPayoutItemId();
|
||||
|
||||
// ### Get Payout Item Status
|
||||
try {
|
||||
$output = \PayPal\Api\PayoutItem::get($payoutItemId, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Payout Item Status", "PayoutItem", null, $payoutItemId, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Payout Item Status", "PayoutItem", $output->getPayoutItemId(), null, $output);
|
||||
|
||||
return $output;
|
||||
Reference in New Issue
Block a user