Creates an invoice. Include invoice details including merchant information in the request.
public create ( |
||
$apiContext | is the APIContext for this call. It can be used to pass dynamic configuration and credentials. | |
$restCall | is the Rest Call Service that is used to make rest calls | |
return |
public function testCreate() { $request = $this->operation['request']['body']; $obj = new Invoice($request); $result = $obj->create(null, $this->mockPayPalRestCall); $this->assertNotNull($result); self::$obj = $result; return $result; }
$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;
/** * @dataProvider mockProvider * @param Invoice $obj */ public function testCreate($obj, $mockApiContext) { $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock(); $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(self::getJson())); $result = $obj->create($mockApiContext, $mockPayPalRestCall); $this->assertNotNull($result); }
public function createInvoice($params = null) { if (!$params) { return false; } $invoice = new Invoice(); // ### Invoice Info // Fill in all the information that is // required for invoice APIs $invoice->setMerchantInfo(new MerchantInfo())->setBillingInfo(array(new BillingInfo())); // ### Merchant Info // A resource representing merchant information that can be // used to identify merchant $owner_email = $this->_credentials['business_owner']; $invoice->getMerchantInfo()->setEmail($owner_email); // ### Billing Information // Set the email address for each billing $billing = $invoice->getBillingInfo(); $billing[0]->setEmail($params['email']); $items = []; foreach ($params['items'] as $key => $item) { # code... $items[$key] = new InvoiceItem(); $items[$key]->setName($item['name'])->setQuantity($item['quantity'])->setUnitPrice(new Currency()); $items[$key]->getUnitPrice()->setCurrency($params['currency'])->setValue((double) $item['price']); } // ### Items List $invoice->setItems($items); $request = clone $invoice; try { $invoice->create($this->config); } catch (\Exception $ex) { return $ex; } return $invoice; }