forked from LiveCarta/PayPal-PHP-SDK
Samples for All Invoice Operations including QR Code
- Invoice search method is static now - Shipping Info has proper Phone Params - Small Changes to Image Class - Updated Sample Docs
This commit is contained in:
@@ -102,10 +102,10 @@ try {
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
$invoice->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Invoice Creation", "Invoice", null, $request, $ex);
|
||||
ResultPrinter::printError("Create Invoice", "Invoice", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Invoice Creation", "Invoice", $invoice->getId(), $request, $invoice);
|
||||
ResultPrinter::printResult("Create Invoice", "Invoice", $invoice->getId(), $request, $invoice);
|
||||
|
||||
return $invoice;
|
||||
|
||||
27
sample/invoice/DeleteInvoice.php
Normal file
27
sample/invoice/DeleteInvoice.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// # Delete Invoice Sample
|
||||
// This sample code demonstrate how you can delete
|
||||
// an invoice.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'CreateInvoice.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\CancelNotification;
|
||||
|
||||
try {
|
||||
|
||||
// ### Delete Invoice
|
||||
// Delete invoice object by calling the
|
||||
// `delete` method
|
||||
// on the Invoice class by passing a valid
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$deleteStatus = $invoice->delete($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Delete Invoice", "Invoice", null, $deleteStatus, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Delete Invoice", "Invoice", $invoice->getId(), null, null);
|
||||
@@ -14,7 +14,7 @@ try {
|
||||
// static `get_all` method on the Invoice class.
|
||||
// Refer the method doc for valid values for keys
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$invoices = Invoice::getAll(array('page' => 0, 'page_size' => 4, 'total_count_required' => true), $apiContext);
|
||||
$invoices = Invoice::getAll(array('page' => 0, 'page_size' => 4, 'total_count_required' => "true"), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Lookup Invoice History", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
|
||||
39
sample/invoice/RecordPayment.php
Normal file
39
sample/invoice/RecordPayment.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
// # Record Payment Sample
|
||||
// This sample code demonstrate how you can record
|
||||
// an invoice as paid.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'SendInvoice.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\PaymentDetail;
|
||||
|
||||
try {
|
||||
// ### Record Object
|
||||
// Create a PaymentDetail object, and fill in the required fields
|
||||
// You can use the new way of injecting json directly to the object.
|
||||
$record = new PaymentDetail(
|
||||
'{
|
||||
"method" : "CASH",
|
||||
"date" : "2014-07-06 03:30:00 PST",
|
||||
"note" : "Cash received."
|
||||
}'
|
||||
);
|
||||
|
||||
// ### Record Payment for Invoice
|
||||
// Record a payment on invoice object by calling the
|
||||
// `recordPayment` method
|
||||
// on the Invoice class by passing a valid
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$recordStatus = $invoice->recordPayment($record, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Payment for Invoice", "Invoice", null, $recordStatus, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Payment for Invoice", "Invoice", $invoice->getId(), $record, null);
|
||||
|
||||
return $invoice;
|
||||
38
sample/invoice/RecordRefund.php
Normal file
38
sample/invoice/RecordRefund.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
// # Record Refund Sample
|
||||
// This sample code demonstrate how you can record
|
||||
// an invoice as refunded.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'RecordPayment.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\RefundDetail;
|
||||
|
||||
try {
|
||||
// ### Record Object
|
||||
// Create a RefundDetail object, and fill in the required fields
|
||||
// You can use the new way of injecting json directly to the object.
|
||||
$refund = new RefundDetail(
|
||||
'{
|
||||
"date" : "2014-07-06 03:30:00 PST",
|
||||
"note" : "Refund provided by cash."
|
||||
}'
|
||||
);
|
||||
|
||||
// ### Record Refund for Invoice
|
||||
// Record a refund on invoice object by calling the
|
||||
// `recordRefund` method
|
||||
// on the Invoice class by passing a valid
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$refundStatus = $invoice->recordRefund($refund, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Refund for Invoice", "Invoice", null, $refundStatus, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Refund for Invoice", "Invoice", $invoice->getId(), $refund, null);
|
||||
|
||||
return $invoice;
|
||||
@@ -37,5 +37,5 @@ ResultPrinter::printResult("Retrieved QR Code for Invoice", "Invoice", $invoice-
|
||||
// In PHP, there are many ways to present an images.
|
||||
// One of the ways, you could directly inject the base64-encoded string
|
||||
// with proper image information in front of it.
|
||||
echo '<img src="data:image/png;base64,'. $image->getImageBase64() . '" alt="Invoice QR Code" />';
|
||||
echo '<img src="data:image/png;base64,'. $image->getImage() . '" alt="Invoice QR Code" />';
|
||||
|
||||
|
||||
36
sample/invoice/SearchInvoices.php
Normal file
36
sample/invoice/SearchInvoices.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
// # Search Invoices Sample
|
||||
// This sample code demonstrate how you can
|
||||
// search invoices from history.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'CreateInvoice.php';
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\Search;
|
||||
|
||||
try {
|
||||
// ### Search Object
|
||||
// Fill up your search criteria for Invoice search.
|
||||
// Using the new way to inject raw json string to constructor
|
||||
$search = new Search(
|
||||
'{
|
||||
"start_invoice_date" : "2010-05-10 PST",
|
||||
"end_invoice_date" : "2019-05-11 PST",
|
||||
"page" : 1,
|
||||
"page_size" : 20,
|
||||
"total_count_required" : true
|
||||
}'
|
||||
);
|
||||
|
||||
// ### Search Invoices
|
||||
// Retrieve the Invoice History object by calling the
|
||||
// static `search` method on the Invoice class.
|
||||
// Refer the method doc for valid values for keys
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$invoices = Invoice::search($search, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Search Invoice", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
ResultPrinter::printResult("Search Invoice", "Invoice", null, $search, $invoices);
|
||||
BIN
sample/invoice/images/sample.png
Normal file
BIN
sample/invoice/images/sample.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user