/** * @test */ public function testCreateAndSendInvoice() { $item1 = new InvoiceItemType('item_name1', '1', '1'); $item2 = new InvoiceItemType('item_name2', '2', '2'); $items = array($item1, $item2); $itemList = new InvoiceItemListType(); $itemList->item = $items; $invoice = new InvoiceType('*****@*****.**', '*****@*****.**', $itemList, 'USD', 'DueOnReceipt'); $requestEnvelope = new RequestEnvelope(); $requestEnvelope->errorLanguage = "en_US"; $createInvoiceRequest = new CreateInvoiceRequest($requestEnvelope, $invoice); $invoice_service = new InvoiceService(); $ret = $invoice_service->CreateAndSendInvoice($createInvoiceRequest, 'jb-us-seller_api1.paypal.com'); $this->assertNotNull($ret); $this->assertNotNull($ret->invoiceID); $this->assertEquals(0, count($ret->error)); }
Configuration::getAcctAndConfig() returns array that contains credential and config parameters */ $invoiceService = new InvoiceService(Configuration::getAcctAndConfig()); // required in third party permissioning if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) { $cred = new PPSignatureCredential("jb-us-seller_api1.paypal.com", "WX4WTU3S8MY44S7F", "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy"); $cred->setThirdPartyAuthorization(new PPTokenAuthorization($_POST['accessToken'], $_POST['tokenSecret'])); } try { /* * ## Making API call Invoke the appropriate method corresponding to API in service wrapper object */ if ($_POST['accessToken'] != null && $_POST['tokenSecret'] != null) { $createAndSendInvoiceResponse = $invoiceService->CreateAndSendInvoice($createAndSendInvoiceRequest, $cred); } else { $createAndSendInvoiceResponse = $invoiceService->CreateAndSendInvoice($createAndSendInvoiceRequest); } } catch (Exception $ex) { require_once 'error.php'; exit; } echo "<table>"; echo "<tr><td>Ack :</td><td><div id='Ack'>" . $createAndSendInvoiceResponse->responseEnvelope->ack . "</div> </td></tr>"; echo "<tr><td>InvoiceID :</td><td><div id='InvoiceID'>" . $createAndSendInvoiceResponse->invoiceID . "</div> </td></tr>"; echo "</table>"; require 'ShowAllResponse.php'; echo "<pre>"; var_dump($createAndSendInvoiceResponse); echo "</pre>";