Skip to content

Instantly share code, notes, and snippets.

@ChrisFlannagan
Last active April 27, 2016 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisFlannagan/325da9c8362e3980a6fbcef0b4881001 to your computer and use it in GitHub Desktop.
Save ChrisFlannagan/325da9c8362e3980a6fbcef0b4881001 to your computer and use it in GitHub Desktop.
<?php
$invoice = new Invoice();
// ### Invoice Info
$invoice
->setMerchantInfo( new MerchantInfo() )
->setBillingInfo( array( new BillingInfo() ) )
->setNote( "Thank you, customer!" )
->setPaymentTerm( new PaymentTerm() )
->setShippingInfo( new ShippingInfo() )
->setTerms( "By paying your invoice you are agreeing ... set your terms here");
// ### Merchant Info
$invoice->getMerchantInfo()
->setEmail( "your@email.com" )
->setFirstName( "YourFirstName" )
->setLastName( "YourLastName" )
->setbusinessName( "Your Company LLC" )
->setAddress( new Address() );
// The address used for creating the invoice
$invoice->getMerchantInfo()->getAddress()
->setLine1( "1111 Somewhere Circle" )
->setCity( "CityName" )
->setState( "AK" )
->setPostalCode( "12345" )
->setCountryCode( "US" );
// ### Billing Information
// Set the email address for each billing
$billing = $invoice->getBillingInfo();
$billing[0]
->setEmail( "person@beingbilled.com" );
// ### Items List
$items = array();
$items[0] = new InvoiceItem();
$items[0]
->setName( "Item Name" )
->setQuantity( 1 )
->setUnitPrice( new Currency() );
$items[0]->getUnitPrice()
->setCurrency( "USD" )
->setValue( $anitem['total'] );
if( $tax ) {
$tax = new \PayPal\Api\Tax();
$tax->setPercent( 4 )->setName( "Local Tax" );
items[0]->setTax( $tax );
}
$invoice->getPaymentTerm()
->setTermType( "DUE_ON_RECEIPT" );
$invoice->setItems( $items );
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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment