Skip to content

Commit

Permalink
PPL-170 , cancel invoice version 2 api added.
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasmht committed Jun 28, 2019
1 parent b15628f commit bfaef20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
31 changes: 31 additions & 0 deletions samples/rest/invoice_v2/CancelInvoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use angelleye\PayPal\rest\invoice\InvoiceAPIv2;

// Include required library files.
require_once('../../../autoload.php');
require_once('../../../includes/config.php');

$configArray = array(
'Sandbox' => $sandbox,
'ClientID' => $rest_client_id,
'ClientSecret' => $rest_client_secret,
'LogResults' => $log_results,
'LogPath' => $log_path,
'LogLevel' => $log_level
);
$PayPal = new InvoiceAPIv2($configArray);

$cancelNotification = array(
'subject' => 'Past due', // Subject of the notification.
'note' => 'Canceling invoice', // Note to the payer.
'send_to_invoicer' => true, // Indicates whether to send a copy of the notification to the merchant.
'send_to_recipient' => true, // Indicates whether to send a copy of the notification to the payer.
'additional_recipients' => array(), // Applicable for invoices created with Cc emails. If this field is not in the body, all the cc email addresses added as part of the invoice shall be notified else this field can be used to limit the list of email addresses. Note: additional email addresses are not supported.
);

$InvoiceID = 'INV2-YZZF-D7VN-P2YM-9ZH2'; // Required. Specify the ID of the invoice to cancel.

$returnArray = $PayPal->CancelInvoice($cancelNotification,$InvoiceID);
echo "<pre>";
print_r($returnArray);
5 changes: 2 additions & 3 deletions src/angelleye/PayPal/InvoicingClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,8 @@ public function remind($notification, $apiContext = null, $restCall = null) {
* @return bool
*/
public function cancel($cancelNotification, $apiContext = null, $restCall = null) {
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($cancelNotification, 'cancelNotification');
$payLoad = $cancelNotification->toJSON();

$payLoad = (!empty($cancelNotification)) ? json_encode($cancelNotification) : '';
self::executeCall(
"/v2/invoicing/invoices/{$this->getId()}/cancel", "POST", $payLoad, null, $apiContext, $restCall
);
Expand Down
5 changes: 2 additions & 3 deletions src/angelleye/PayPal/rest/invoice/InvoiceAPIv2.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ public function GetThirdPartyInvoice($invoiceId, $refreshToken)
public function CancelInvoice($cancelNotification, $InvoiceID, $third_party = false, $refesh_token = '')
{
try {
$notify = new CancelNotification();
$this->setArrayToMethods(array_filter($cancelNotification), $notify);

$notify = array_filter($cancelNotification);
$invoice = new InvoicingClass();
$invoice->setId($InvoiceID);
if ($third_party === true && !empty($refesh_token)) {
Expand All @@ -378,7 +377,7 @@ public function CancelInvoice($cancelNotification, $InvoiceID, $third_party = fa

$returnArray['RESULT'] = 'Success';
$returnArray['CANCEL_STATUS'] = $cancelStatus;
$returnArray['RAWREQUEST'] = $requestArray;
$returnArray['RAWREQUEST'] = $requestArray->toJSON();
$returnArray['RAWRESPONSE'] = $cancelStatus;
return $returnArray;
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
Expand Down

0 comments on commit bfaef20

Please sign in to comment.