forked from LiveCarta/PayPal-PHP-SDK
Added invoice samples
This commit is contained in:
37
sample/invoicing/CancelInvoice.php
Normal file
37
sample/invoicing/CancelInvoice.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\CancelNotification;
|
||||
|
||||
try {
|
||||
$invoice = Invoice::get("INV2-CJL7-PF4G-BLQF-5FWG", $apiContext);
|
||||
|
||||
$notify = new CancelNotification();
|
||||
$notify
|
||||
->setSubject("Past due")
|
||||
->setNote("Canceling invoice")
|
||||
->setSendToMerchant(true)
|
||||
->setSendToPayer(true);
|
||||
|
||||
|
||||
$cancelStatus = $invoice->cancel($notify, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Cancel Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Cancel Invoice:</div>
|
||||
<pre><?php var_dump($invoice);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
100
sample/invoicing/CreateInvoice.php
Normal file
100
sample/invoicing/CreateInvoice.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\MerchantInfo;
|
||||
use PayPal\Api\BillingInfo;
|
||||
use PayPal\Api\InvoiceItem;
|
||||
use PayPal\Api\Phone;
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Currency;
|
||||
use PayPal\Api\PaymentTerm;
|
||||
use PayPal\Api\ShippingInfo;
|
||||
|
||||
$invoice = new Invoice();
|
||||
|
||||
$invoice
|
||||
->setMerchantInfo(new MerchantInfo())
|
||||
->setBillingInfo(array(new BillingInfo()))
|
||||
->setItems(array(new InvoiceItem()))
|
||||
->setNote("Medical Invoice 16 Jul, 2013 PST")
|
||||
->setPaymentTerm(new PaymentTerm())
|
||||
->setShippingInfo(new ShippingInfo());
|
||||
|
||||
$invoice->getMerchantInfo()
|
||||
->setEmail("PPX.DevNet-facilitator@gmail.com")
|
||||
->setFirstName("Dennis")
|
||||
->setLastName("Doctor")
|
||||
->setbusinessName("Medical Professionals, LLC")
|
||||
->setPhone(new Phone())
|
||||
->setAddress(new Address());
|
||||
|
||||
$invoice->getMerchantInfo()->getPhone()
|
||||
->setCountryCode("001")
|
||||
->setNationalNumber("5032141716");
|
||||
|
||||
$invoice->getMerchantInfo()->getAddress()
|
||||
->setLine1("1234 Main St.")
|
||||
->setCity("Portland")
|
||||
->setState("OR")
|
||||
->setPostalCode("97217")
|
||||
->setCountryCode("US");
|
||||
|
||||
$billing = $invoice->getBillingInfo();
|
||||
$billing[0]
|
||||
->setEmail("example@example.com");
|
||||
|
||||
$items = $invoice->getItems();
|
||||
$items[0]
|
||||
->setName("Sutures")
|
||||
->setQuantity(100)
|
||||
->setUnitPrice(new Currency());
|
||||
|
||||
$items[0]->getUnitPrice()
|
||||
->setCurrency("USD")
|
||||
->setValue(5);
|
||||
|
||||
$invoice->getPaymentTerm()
|
||||
->setTermType("NET_45");
|
||||
|
||||
$invoice->getShippingInfo()
|
||||
->setFirstName("Sally")
|
||||
->setLastName("Patient")
|
||||
->setBusinessName("Not applicable")
|
||||
->setPhone(new Phone())
|
||||
->setAddress(new Address());
|
||||
|
||||
$invoice->getShippingInfo()->getPhone()
|
||||
->setCountryCode("001")
|
||||
->setNationalNumber("5039871234");
|
||||
|
||||
$invoice->getShippingInfo()->getAddress()
|
||||
->setLine1("1234 Main St.")
|
||||
->setCity("Portland")
|
||||
->setState("OR")
|
||||
->setPostalCode("97217")
|
||||
->setCountryCode("US");
|
||||
|
||||
print(var_dump($invoice->toArray()));
|
||||
|
||||
try {
|
||||
$invoice->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created Invoice:
|
||||
<?php echo $invoice->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($invoice->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
19
sample/invoicing/GetInvoice.php
Normal file
19
sample/invoicing/GetInvoice.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
$invoiceId = "INV2-9DRB-YTHU-2V9Q-7Q24";
|
||||
|
||||
$invoice = Invoice::get($invoiceId, $apiContext);
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice details</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Invoice: <?php echo $invoiceId;?></div>
|
||||
<pre><?php var_dump($invoice);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
22
sample/invoicing/ListInvoice.php
Normal file
22
sample/invoicing/ListInvoice.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
$invoices = Invoice::get_all($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got invoices </div>
|
||||
<pre><?php var_dump($invoices->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
35
sample/invoicing/RemindInvoice.php
Normal file
35
sample/invoicing/RemindInvoice.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\Notification;
|
||||
|
||||
try {
|
||||
$invoice = Invoice::get("INV2-9CAH-K5G7-2JPL-G4B4", $apiContext);
|
||||
|
||||
$notify = new Notification();
|
||||
$notify
|
||||
->setSubject("Past due")
|
||||
->setNote("Please pay soon")
|
||||
->setSendToMerchant(true);
|
||||
|
||||
$remindStatus = $invoice->remind($notify, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Remind Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Remind Invoice:</div>
|
||||
<pre><?php var_dump($invoice);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
27
sample/invoicing/SendInvoice.php
Normal file
27
sample/invoicing/SendInvoice.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
$invoice = Invoice::get("INV2-9DRB-YTHU-2V9Q-7Q24", $apiContext);
|
||||
|
||||
$sendStatus = $invoice->send($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Send Invoice</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Send Invoice:</div>
|
||||
<pre><?php var_dump($invoice);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user