recreate project
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
// # Cancel Invoice Sample
|
||||
// This sample code demonstrate how you can cancel
|
||||
// an invoice.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'SendInvoice.php';
|
||||
|
||||
use PayPal\Api\CancelNotification;
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
|
||||
// ### Cancel Notification Object
|
||||
// This would send a notification to both merchant as well
|
||||
// the payer about the cancellation. The information of
|
||||
// merchant and payer is retrieved from the invoice details
|
||||
$notify = new CancelNotification();
|
||||
$notify
|
||||
->setSubject("Past due")
|
||||
->setNote("Canceling invoice")
|
||||
->setSendToMerchant(true)
|
||||
->setSendToPayer(true);
|
||||
|
||||
|
||||
// ### Cancel Invoice
|
||||
// Cancel invoice object by calling the
|
||||
// static `cancel` method
|
||||
// on the Invoice class by passing a valid
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$cancelStatus = $invoice->cancel($notify, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Cancel Invoice", "Invoice", null, $notify, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Cancel Invoice", "Invoice", $invoice->getId(), $notify, null);
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
// # Create Invoice Sample
|
||||
// This sample code demonstrate how you can create
|
||||
// an invoice.
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\BillingInfo;
|
||||
use PayPal\Api\Cost;
|
||||
use PayPal\Api\Currency;
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\InvoiceAddress;
|
||||
use PayPal\Api\InvoiceItem;
|
||||
use PayPal\Api\MerchantInfo;
|
||||
use PayPal\Api\PaymentTerm;
|
||||
use PayPal\Api\Phone;
|
||||
use PayPal\Api\ShippingInfo;
|
||||
|
||||
$invoice = new Invoice();
|
||||
|
||||
// ### Invoice Info
|
||||
// Fill in all the information that is
|
||||
// required for invoice APIs
|
||||
$invoice
|
||||
->setMerchantInfo(new MerchantInfo())
|
||||
->setBillingInfo(array(new BillingInfo()))
|
||||
->setNote("Medical Invoice 16 Jul, 2013 PST")
|
||||
->setPaymentTerm(new PaymentTerm())
|
||||
->setShippingInfo(new ShippingInfo());
|
||||
|
||||
// ### Merchant Info
|
||||
// A resource representing merchant information that can be
|
||||
// used to identify merchant
|
||||
$invoice->getMerchantInfo()
|
||||
->setEmail("jaypatel512-facilitator@hotmail.com")
|
||||
->setFirstName("Dennis")
|
||||
->setLastName("Doctor")
|
||||
->setbusinessName("Medical Professionals, LLC")
|
||||
->setPhone(new Phone())
|
||||
->setAddress(new Address());
|
||||
|
||||
$invoice->getMerchantInfo()->getPhone()
|
||||
->setCountryCode("001")
|
||||
->setNationalNumber("5032141716");
|
||||
|
||||
// ### Address Information
|
||||
// The address used for creating the invoice
|
||||
$invoice->getMerchantInfo()->getAddress()
|
||||
->setLine1("1234 Main St.")
|
||||
->setCity("Portland")
|
||||
->setState("OR")
|
||||
->setPostalCode("97217")
|
||||
->setCountryCode("US");
|
||||
|
||||
// ### Billing Information
|
||||
// Set the email address for each billing
|
||||
$billing = $invoice->getBillingInfo();
|
||||
$billing[0]
|
||||
->setEmail("example@example.com");
|
||||
|
||||
$billing[0]->setBusinessName("Jay Inc")
|
||||
->setAdditionalInfo("This is the billing Info")
|
||||
->setAddress(new InvoiceAddress());
|
||||
|
||||
$billing[0]->getAddress()
|
||||
->setLine1("1234 Main St.")
|
||||
->setCity("Portland")
|
||||
->setState("OR")
|
||||
->setPostalCode("97217")
|
||||
->setCountryCode("US");
|
||||
|
||||
// ### Items List
|
||||
// You could provide the list of all items for
|
||||
// detailed breakdown of invoice
|
||||
$items = array();
|
||||
$items[0] = new InvoiceItem();
|
||||
$items[0]
|
||||
->setName("Sutures")
|
||||
->setQuantity(100)
|
||||
->setUnitPrice(new Currency());
|
||||
|
||||
$items[0]->getUnitPrice()
|
||||
->setCurrency("USD")
|
||||
->setValue(5);
|
||||
|
||||
// #### Tax Item
|
||||
// You could provide Tax information to each item.
|
||||
$tax = new \PayPal\Api\Tax();
|
||||
$tax->setPercent(1)->setName("Local Tax on Sutures");
|
||||
$items[0]->setTax($tax);
|
||||
|
||||
// Second Item
|
||||
$items[1] = new InvoiceItem();
|
||||
// Lets add some discount to this item.
|
||||
$item1discount = new Cost();
|
||||
$item1discount->setPercent("3");
|
||||
$items[1]
|
||||
->setName("Injection")
|
||||
->setQuantity(5)
|
||||
->setDiscount($item1discount)
|
||||
->setUnitPrice(new Currency());
|
||||
|
||||
$items[1]->getUnitPrice()
|
||||
->setCurrency("USD")
|
||||
->setValue(5);
|
||||
|
||||
// #### Tax Item
|
||||
// You could provide Tax information to each item.
|
||||
$tax2 = new \PayPal\Api\Tax();
|
||||
$tax2->setPercent(3)->setName("Local Tax on Injection");
|
||||
$items[1]->setTax($tax2);
|
||||
|
||||
$invoice->setItems($items);
|
||||
|
||||
// #### Final Discount
|
||||
// You can add final discount to the invoice as shown below. You could either use "percent" or "value" when providing the discount
|
||||
$cost = new Cost();
|
||||
$cost->setPercent("2");
|
||||
$invoice->setDiscount($cost);
|
||||
|
||||
$invoice->getPaymentTerm()
|
||||
->setTermType("NET_45");
|
||||
|
||||
// ### Shipping Information
|
||||
$invoice->getShippingInfo()
|
||||
->setFirstName("Sally")
|
||||
->setLastName("Patient")
|
||||
->setBusinessName("Not applicable")
|
||||
->setPhone(new Phone())
|
||||
->setAddress(new InvoiceAddress());
|
||||
|
||||
$invoice->getShippingInfo()->getPhone()
|
||||
->setCountryCode("001")
|
||||
->setNationalNumber("5039871234");
|
||||
|
||||
$invoice->getShippingInfo()->getAddress()
|
||||
->setLine1("1234 Main St.")
|
||||
->setCity("Portland")
|
||||
->setState("OR")
|
||||
->setPostalCode("97217")
|
||||
->setCountryCode("US");
|
||||
|
||||
// ### Logo
|
||||
// You can set the logo in the invoice by providing the external URL pointing to a logo
|
||||
$invoice->setLogoUrl('https://www.paypalobjects.com/webstatic/i/logo/rebrand/ppcom.svg');
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $invoice;
|
||||
|
||||
try {
|
||||
// ### Create Invoice
|
||||
// Create an invoice by calling the invoice->create() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
$invoice->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Create Invoice", "Invoice", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Create Invoice", "Invoice", $invoice->getId(), $request, $invoice);
|
||||
|
||||
return $invoice;
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
|
||||
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) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Delete Invoice", "Invoice", null, $deleteStatus, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Delete Invoice", "Invoice", $invoice->getId(), null, null);
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// # Get Invoice Sample
|
||||
// This sample code demonstrate how you can retrieve
|
||||
// an invoice.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'CreateInvoice.php';
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
$invoiceId = $invoice->getId();
|
||||
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Invoice class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoiceId, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $invoice);
|
||||
|
||||
return $invoice;
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
// # List Invoices Sample
|
||||
// This sample code demonstrate how you can get
|
||||
// all invoice from history.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'CreateInvoice.php';
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
// ### Retrieve Invoices
|
||||
// Retrieve the Invoice History object by calling the
|
||||
// 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);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Lookup Invoice History", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices);
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Payment for Invoice", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Payment for Invoice", "Invoice", $invoice->getId(), $record, null);
|
||||
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Invoice class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoice->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $invoice);
|
||||
|
||||
return $invoice;
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Refund for Invoice", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Refund for Invoice", "Invoice", $invoice->getId(), $refund, null);
|
||||
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Invoice class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoice->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $invoice);
|
||||
|
||||
return $invoice;
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
// # Remind Invoice Sample
|
||||
// This sample code demonstrate how you can remind
|
||||
// an invoice to the payer
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'SendInvoice.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\Notification;
|
||||
|
||||
try {
|
||||
|
||||
// ### Notification Object
|
||||
// This would send a notification to both merchant as well
|
||||
// the payer. The information of merchant
|
||||
// and payer is retrieved from the invoice details
|
||||
$notify = new Notification();
|
||||
$notify
|
||||
->setSubject("Past due")
|
||||
->setNote("Please pay soon")
|
||||
->setSendToMerchant(true);
|
||||
|
||||
// ### Remind Invoice
|
||||
// Remind the notifiers by calling the
|
||||
// `remind` method
|
||||
// on the Invoice class by passing a valid
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$remindStatus = $invoice->remind($notify, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Remind Invoice", "Invoice", null, $notify, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Remind Invoice", "Invoice", null, $notify, null);
|
||||
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Invoice class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoice->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $invoice);
|
||||
|
||||
return $invoice;
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// # Retrieve QR Code for Invoice Sample
|
||||
// Specify an invoice ID to get a QR code (image) that corresponds to the invoice ID. A QR code for an invoice can be added to a paper or PDF invoice. When a customer uses their mobile device to scan the QR code, the customer is redirected to the PayPal mobile payment flow, where they can pay online with PayPal or a credit card.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'SendInvoice.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
|
||||
// ### Retrieve QR Code of Sent Invoice
|
||||
// Retrieve QR Code of Sent Invoice by calling the
|
||||
// `qrCode` method
|
||||
// on the Invoice class by passing a valid
|
||||
// notification object
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$image = Invoice::qrCode($invoice->getId(), array('height' => '300', 'width' => '300'), $apiContext);
|
||||
|
||||
// ### Optionally Save to File
|
||||
// This is not a required step. However, if you want to store this image as a file, you can use
|
||||
// 'saveToFile' method with proper file name.
|
||||
// This will save the image as /samples/invoice/images/sample.png
|
||||
$path = $image->saveToFile("images/sample.png");
|
||||
|
||||
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Retrieved QR Code for Invoice", "Invoice", $invoice->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Retrieved QR Code for Invoice", "Invoice", $invoice->getId(), null, $image);
|
||||
|
||||
// ### Show the Image
|
||||
// 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->getImage() . '" alt="Invoice QR Code" />';
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Search Invoice", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Search Invoice", "Invoice", null, $search, $invoices);
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// # Create Invoice Sample
|
||||
// This sample code demonstrate how you can send
|
||||
// a legitimate invoice to the payer
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'CreateInvoice.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
|
||||
// ### Send Invoice
|
||||
// Send a legitimate invoice to the payer
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
$sendStatus = $invoice->send($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Send Invoice", "Invoice", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Send Invoice", "Invoice", $invoice->getId(), null, null);
|
||||
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Invoice class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoice->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $invoice);
|
||||
|
||||
return $invoice;
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
// # Update Invoice Sample
|
||||
// This sample code demonstrate how you can update
|
||||
// an invoice.
|
||||
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = require 'CreateInvoice.php';
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $invoice;
|
||||
|
||||
// ### Update Invoice
|
||||
// Lets update some information
|
||||
$invoice->setInvoiceDate("2014-12-16 PST");
|
||||
|
||||
// ### NOTE: These are the work-around added to the
|
||||
// sample, to get past the bug in PayPal APIs.
|
||||
// There is already an internal ticket #PPTIPS-1932 created for it.
|
||||
$invoice->setDiscount(null);
|
||||
$billingInfo = $invoice->getBillingInfo()[0];
|
||||
$billingInfo->setAddress(null);
|
||||
$invoice->getPaymentTerm()->setDueDate(null);
|
||||
|
||||
try {
|
||||
// ### Update Invoice
|
||||
// Update an invoice by calling the invoice->update() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
$invoice->update($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Invoice Updated", "Invoice", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Invoice Updated", "Invoice", $invoice->getId(), $request, $invoice);
|
||||
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Invoice class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$invoice = Invoice::get($invoice->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult("Get Invoice (Not Required - For Sample Only)", "Invoice", $invoice->getId(), $invoice->getId(), $invoice);
|
||||
|
||||
return $invoice;
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user