PayPal\Api\Capture::refund PHP Method

refund() public method

Refund a captured payment by passing the capture_id in the request URI. In addition, include an amount object in the body of the request JSON.
Deprecation: Please use #refundCapturedPayment instead.
public refund ( Refund $refund, ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : Refund
$refund Refund
$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 Refund
    public function refund($refund, $apiContext = null, $restCall = null)
    {
        ArgumentValidator::validate($this->getId(), "Id");
        ArgumentValidator::validate($refund, 'refund');
        $payLoad = $refund->toJSON();
        $json = self::executeCall("/v1/payments/capture/{$this->getId()}/refund", "POST", $payLoad, null, $apiContext, $restCall);
        $ret = new Refund();
        $ret->fromJson($json);
        return $ret;
    }

Usage Example

示例#1
0
 /**
  * @dataProvider mockProvider
  * @param Capture $obj
  */
 public function testRefund($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(RefundTest::getJson()));
     $refund = RefundTest::getObject();
     $result = $obj->refund($refund, $mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }