Generate a QR code for an invoice by passing the invoice ID to the request URI. The request generates a QR code that is 500 pixels in width and height. You can change the dimensions of the returned code by specifying optional query parameters.
public static qrCode ( string $invoiceId, array $params = [], |
||
$invoiceId | string | |
$params | array | |
$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 | PayPal\Api\Image |
/** * @dataProvider mockProvider * @param Invoice $obj */ public function testQrCode($obj, $mockApiContext) { $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock(); $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(ImageTest::getJson())); $result = $obj->qrCode("invoiceId", array(), $mockApiContext, $mockPayPalRestCall); $this->assertNotNull($result); }
<?php // # Retrieve QR Code for Invoice Sample // Specify an invoice ID to get a QR code (image) that corresponds to the invoice ID. A QR code for an invoice can be added to a paper or PDF invoice. When a customer uses their mobile device to scan the QR code, the customer is redirected to the PayPal mobile payment flow, where they can pay online with PayPal or a credit card. /** @var Invoice $invoice */ $invoice = (require 'SendInvoice.php'); use PayPal\Api\Invoice; try { // ### Retrieve QR Code of Sent Invoice // Retrieve QR Code of Sent Invoice by calling the // `qrCode` method // on the Invoice class by passing a valid // notification object // (See bootstrap.php for more on `ApiContext`) $image = Invoice::qrCode($invoice->getId(), array('height' => '300', 'width' => '300'), $apiContext); // ### Optionally Save to File // This is not a required step. However, if you want to store this image as a file, you can use // 'saveToFile' method with proper file name. // This will save the image as /samples/invoice/images/sample.png $path = $image->saveToFile("images/sample.png"); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Retrieved QR Code for Invoice", "Invoice", $invoice->getId(), null, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Retrieved QR Code for Invoice", "Invoice", $invoice->getId(), null, $image); // ### Show the Image // In PHP, there are many ways to present an images. // One of the ways, you could directly inject the base64-encoded string // with proper image information in front of it.
/** * @depends testSend * @param $invoice Invoice * @return Invoice */ public function testQRCode($invoice) { $result = Invoice::qrCode($invoice->getId(), array(), null, $this->mockPayPalRestCall); $this->assertNotNull($result); $this->assertNotNull($result->getImage()); }