forked from LiveCarta/PayPal-PHP-SDK
Removing Dependency from SDK Core Project
- Copied files required for Rest API SDK - Removed PPApiContext and directly connected APIContext with PPConfigManager - Removed duplicate data storage of configuration and credentials. - Code Style Fixes - Remove build.xml file as it is not required anymore - Updated the samples - Updated the documentations
This commit is contained in:
57
sample/invoice/CancelInvoice.php
Normal file
57
sample/invoice/CancelInvoice.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
// # Cancel Invoice Sample
|
||||
// This sample code demonstrate how you can cancel
|
||||
// an invoice.
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\CancelNotification;
|
||||
|
||||
try {
|
||||
// ### Retrieve Invoice
|
||||
// Retrieve the invoice object by calling the
|
||||
// static `get` method
|
||||
// on the Payment class by passing a valid
|
||||
// Invoice ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$invoice = Invoice::get("INV2-CJL7-PF4G-BLQF-5FWG", $apiContext);
|
||||
|
||||
// ### 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 (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 echo $invoice->toJSON(JSON_PRETTY_PRINT); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
119
sample/invoice/CreateInvoice.php
Normal file
119
sample/invoice/CreateInvoice.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
// # Create Invoice Sample
|
||||
// This sample code demonstrate how you can create
|
||||
// an invoice.
|
||||
|
||||
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 Info
|
||||
// Fill in all the information that is
|
||||
// required for invoice APIs
|
||||
$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());
|
||||
|
||||
// ### Merchant Info
|
||||
// A resource representing merchant information that can be
|
||||
// used to identify merchant
|
||||
$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");
|
||||
|
||||
// ### 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");
|
||||
|
||||
// ### Items List
|
||||
// You could provide the list of all items for
|
||||
// detailed breakdown of invoice
|
||||
$items = $invoice->getItems();
|
||||
$items[0]
|
||||
->setName("Sutures")
|
||||
->setQuantity(100)
|
||||
->setUnitPrice(new Currency());
|
||||
|
||||
$items[0]->getUnitPrice()
|
||||
->setCurrency("USD")
|
||||
->setValue(5);
|
||||
|
||||
$invoice->getPaymentTerm()
|
||||
->setTermType("NET_45");
|
||||
|
||||
// ### Shipping Information
|
||||
$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");
|
||||
|
||||
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 (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Invoice Creation</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created Invoice:
|
||||
<?php echo $invoice->getId(); ?>
|
||||
</div>
|
||||
<pre><?php echo $invoice->toJSON(JSON_PRETTY_PRINT); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
35
sample/invoice/GetInvoice.php
Normal file
35
sample/invoice/GetInvoice.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// # Get Invoice Sample
|
||||
// This sample code demonstrate how you can retrieve
|
||||
// an invoice.
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
$invoiceId = "INV2-9DRB-YTHU-2V9Q-7Q24";
|
||||
|
||||
// ### 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 (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup invoice details</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Invoice: <?php echo $invoiceId;?></div>
|
||||
<pre><?php echo $invoice->toJSON(JSON_PRETTY_PRINT); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
32
sample/invoice/ListInvoice.php
Normal file
32
sample/invoice/ListInvoice.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
// # List Invoices Sample
|
||||
// This sample code demonstrate how you can get
|
||||
// all invoice from history.
|
||||
|
||||
require __DIR__ . '/../bootstrap.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::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 echo $invoices->toJSON(JSON_PRETTY_PRINT); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
55
sample/invoice/RemindInvoice.php
Normal file
55
sample/invoice/RemindInvoice.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
// # Remind Invoice Sample
|
||||
// This sample code demonstrate how you can remind
|
||||
// an invoice to the payer
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
use PayPal\Api\Notification;
|
||||
|
||||
try {
|
||||
// ### 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`)
|
||||
$invoice = Invoice::get("INV2-9CAH-K5G7-2JPL-G4B4", $apiContext);
|
||||
|
||||
// ### 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 (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 echo $invoice->toJSON(JSON_PRETTY_PRINT); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
40
sample/invoice/SendInvoice.php
Normal file
40
sample/invoice/SendInvoice.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
// # Create Invoice Sample
|
||||
// This sample code demonstrate how you can send
|
||||
// a legitimate invoice to the payer
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Invoice;
|
||||
|
||||
try {
|
||||
// ### 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`)
|
||||
$invoice = Invoice::get("INV2-9DRB-YTHU-2V9Q-7Q24", $apiContext);
|
||||
|
||||
// ### 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 (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 echo $invoice->toJSON(JSON_PRETTY_PRINT); ?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user