cancel() public static method

Cancels the unclaimed payment using the items id passed in the request URI. 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.
public static cancel ( string $payoutItemId, ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : PayoutItemDetails
$payoutItemId string
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPal\Transport\PayPalRestCall is the Rest Call Service that is used to make rest calls
return PayoutItemDetails
Esempio n. 1
0
 /**
  * @dataProvider mockProvider
  * @param PayoutItem $obj
  */
 public function testCancel($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(PayoutItemDetailsTest::getJson()));
     $result = $obj->cancel("payoutItemId", $mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }
<?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);
        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.
        ResultPrinter::printError("Cancel Unclaimed Payout Item", "PayoutItem", null, $payoutItemId, new Exception("Payout Item Status is not UNCLAIMED"));
    }
} catch (Exception $ex) {
    ResultPrinter::printError("Cancel Unclaimed Payout Item", "PayoutItem", null, $payoutItemId, $ex);
    exit(1);
}
return $output;
Esempio n. 3
0
 /**
  * @depends testCreate
  * @param $payoutBatch PayoutBatch
  * @return PayoutBatch
  */
 public function testCancel($payoutBatch)
 {
     $items = $payoutBatch->getItems();
     $item = $items[0];
     if ($item->getTransactionStatus() != 'UNCLAIMED') {
         $this->markTestSkipped('Transaction status needs to be Unclaimed for this test ');
         return;
     }
     $result = PayoutItem::cancel($item->getPayoutItemId(), $this->apiContext, $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());
     $this->assertEquals('RETURNED', $result->getTransactionStatus());
 }