PayPal Here Web SDK
Last updated: Sept 19th, 7:22pm
Overview
The PPH Web SDK is a single page script and is designed to be integrated on your final Payment or Checkout page.
The following restrictions apply to this SDK:
- Available only to the US region.
- Available only on Windows desktop/laptop browsers. Phone/Tablet mobile browsers are not supported.
- USB is the only supported connection method.
- No multi-card reader support: if two USB readers are connected, the SDK automatically connects to the first one it recognizes.
Integration
Similar to PayPal Here's iOS and Android SDKs, the Web SDK uses standard OAuth to authenticate. Make sure that you have already created your REST App and have reviewed the Merchant Onboarding section of the documentation. Also, review the GitHub repository for the latest script link and SDK version information.
Setup
PayPal Here Web SDK uses a headless standalone desktop application (PPHWebInterface) to interact with connected card readers. The one-time setup must be done before you can process payments and must be done on each machine. PayPal recommends using a separate setup page for the setupUI
. Include the following snippet in your setup page:
1<button type="button" id='setupPPH' onclick='onSetupPayPalHereBtnClicked()'>Setup PayPal Here</button>
1function onSetupPayPalHereBtnClicked() {2 pphwebsdk.Setup.startUIFlow().then(function (completionStep) {3 // PPHWebInterface has been installed and, if clicked, a test of the connected card reader was completed.4 // setup is complete5 });6}
To make sure that the setup has been completed on your computer prior to processing payments, call isSetupComplete()
. If it hasn’t completed yet, call the startUIFlow
as mentioned above. Otherwise, if it has already completed, you can continue on to your payment flow.
1pphwebsdk.Setup.isSetupComplete().then(function() {2 // Continue to payment flow3}).catch(function(err) {4 // Run startUIFlow to setup SDK5});
Accepting payments
Once everything has been set up, follow the steps in the order listed here to accept payments:
-
Create identity. This is similar to the
initializeMerchant
function of the iOS and Android SDKs. It tells the SDK which merchant account is receiving the payment and in which environment. For more information on token management, please refer to the PayPal Here Onboarding Process.1var identity = pphwebsdk.Identity.create(access_token).refreshUrl(refresh_url).environment(environment);Attribute Type Description access_token
String Required
Valid access token for the merchant account.refresh_url
String Optional
URL that the SDK will reach out to refresh the access token when it expires.environment
Enum Required
Needs to either bepphwebsdk.Types.Environment.LIVE
orpphwebsdk.Types.Environment.SANDBOX
. -
Payment configuration. Even though you can process transactions with default values, the SDK allows you to customize the flow depending on your needs. Payment configuration is required for subscribing to events and customizing the payment flow. The following code snippet creates a default configuration:
1var payment_config = pphwebsdk.PaymentConfiguration.create();Starting with version 1.1.1, the reader connection is handled by the payment configuration. You will create a reader object and then specify the connection type and reader manufacturer.
1var reader = payment_config.reader();2 reader.connectionType(pphwebsdk.Types.ReaderConnectionType.USB);3 reader.manufacturer(pphwebsdk.Types.Manufacturers.MIURA);Object Description Values connectionType()
Accepts enum value for the reader connection type. pphwebsdk.Types.ReaderConnectionType.USB
manufacturer()
Accepts enum value for the reader being connected to. pphwebsdk.Types.Manufacturers.MIURA
pphwebsdk.Types.Manufacturers.INGENICO
pphwebsdk.Types.Manufacturers.VERIFONE
-
Create order. In order to process payments or refunds, you need an order. The following snippet shows how to create an order for a payment and add items to it:
1var order = pphwebsdk.Order.create();2 order.item('Cake').price(1.00).quantity(3);3 order.item('Coffee').price(2.00).quantity(3); -
Process payment. Once you have the identity, payment configuration, and order ready, you can then accept the payment. The following snippet shows how to process a sale transaction:
1var payment = pphwebsdk.Payment.create(identity, payment_config);2 payment.for(order).as(pphwebsdk.Types.PaymentMethod.CARD).sale();As part of the payment flow, the SDK will automatically prompt for any reader firmware updates that may be available. You'll need to subscribe to the success or failure events on the
Reader
object to get the status of said updates:1// Readers will automatically prompt for the update if there is one available. There are two events, on the Reader object, that will fire after an update.2pphwebsdk.Reader.subscribe3 .firmwareUpdateSuccess(function (upgradedDevice) {4 // Reader firmware update was a success5 })6 .firmwareUpdateFailure(function (err) {7 // Reader firmware update failed - handle accordingly8 });When the reader firmware update is done successfully, the SDK will simply continue on with the payment flow without you having to action anything. If the not now option was pressed on the reader firmware update UI, then you will need to call
pendingUpdateInstall()
to trigger that firmware update flow and install the update. If there is a firmware update, it needs to be completed successfully before you will be able to process another transaction. You can also callpendingUpdateInstall()
prior to making a payment if you'd like to proactively check for any firmware updates available.1pphwebsdk.Reader.pendingUpdateInstall();
Object references
The following tables outline the different options for the objects mentioned above:
Payment configuration
Object | Description | Default |
---|---|---|
create() |
Creates a new PaymentConfiguration . |
N/A |
subscribe |
Subscribe to payment events. | No events are subscribed to. |
useQuickChip |
Enables Quick Chip functionality and disables contactless payments. | Disabled. |
showPromptInReader |
When used with the Chip Card Reader, this displays the prompt to Tap/Insert/Swipe the card on the card reader screen. | Enabled. |
showPromptInClient |
This displayes the prompt, in the client application, to Tap/Insert/Swipe the card. | Enabled. |
hidePromptInReader |
When used with the Chip Card Reader, this hides the prompt to Tap/Insert/Swipe the card on the card reader screen. | Disabled. |
hidePromptInClient |
This hides the prompt, in the client application, to Tap/Insert/Swipe the card. | Disabled. |
Payment
Object | Description |
---|---|
for(order) |
Reference to the order instance. |
as(paymentMethod) |
Reference to payment method types. |
sale() |
Process the payment as a sale. |
authorize() |
Process the payment as an authorization to be captured later. |
refund() |
Process a refund. |
Order
Object | Description |
---|---|
item(name) |
Create a new item. |
remove(item) |
Remove an item. |
number(orderNumber) |
Custom order number. Similar to the invoice number of iOS and Android. |
tip(amount) |
Adds gratuity to the order. |
PaymentMethod types
Refer to the samples for more details on the usage of these payment method types.
Type | Values |
---|---|
PaymentMethod |
CASH , CHECK , KEYIN , CARD |
Item
Object | Description |
---|---|
quantity(quantity) |
Quantity of given item(s). |
price(price) |
Price of the individual item. |
Order for refund
Object | Description |
---|---|
create() |
Create a refund for an existing order. |
on(transactionNumber) |
This is the transaction number that was received as part of the transaction record with the onPaymentSuccess event. |
with(invoiceId) |
This is the PayPal invoice ID that was received as part of the transaction record with the onPaymentSuccess event. |
for(refundAmount) |
Amount to be refunded. Can either be a partial or full refund. |
Events
Event handlers are functions that are subscribed to as part of the PaymentConfiguration
. These events may have arguments as mentioned below. Refer to the samples for details on how these events are implemented.
Event | Argument | Description |
---|---|---|
onMerchantInitializeSuccess |
merchant |
The merchant object will contain necessary information about the merchant account. |
onMerchantInitializeFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
onConnectReaderSuccess |
details |
The details object will contain necessary information about the connected reader. |
onConnectReaderFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
NoDevicesFound |
empty | This event fires when there are no devices able to be connected to. |
onPaymentSuccess |
transactionRecord |
The transactionRecord will contain the transactionNumber and PayPal invoiceId . |
onPaymentFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
onRefundSuccess |
transactionRecord |
The transactionRecord will contain the transactionNumber for the refund. |
onRefundFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
onCaptureSuccess |
captureId |
The captureId is the transaction ID from captureing the authorization. |
onCaptureFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
onVoidSuccess |
empty | This event is fired when an authorization has been successfully voided. |
onVoidFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
onVaultSuccess |
vaultRecord |
The vaultRecord will contain the vaultId that is used later with Braintree code to charge the stored payment method. |
onVaultFailure |
error |
The error object will contain necessary information about the error to better understand what went wrong. |
Samples
Below are some simple samples for event handlers, reader updates, payment, and refund:
Event handlers
1var payment_config = pphwebsdk.PaymentConfiguration.create();2 payment_config.subscribe3 .onConnectReaderSuccess(function (details) {4 //Details of card reader provided5 })6 .onConnectReaderFailure(function (err) {7 //Unable to connect to reader - handle error scenario8 })9 .onMerchantInitializeSuccess(function (merchant) {10 //Merchant initialized successfully11 })12 .onMerchantInitializeFailure(function (err) {13 //Unable to intialize merchant - handle error scenario14 })15 .onPaymentSuccess(function (txnRecord) {16 //Payment success17 })18 .onPaymentFailure(function (err) {19 //Payment failed - handle error scenario20 });
Payment with full options
1var identity = pphwebsdk.Identity.create(access_token).refreshUrl(refresh_url).environment(environment);23 var payment_config = pphwebsdk.PaymentConfiguration.create();4 payment_config.subscribe5 .onConnectReaderSuccess(function (details) {6 //Details of card reader provided7 })8 .onConnectReaderFailure(function (err) {9 //Unable to connect to reader - handle error scenario10 })11 .onMerchantInitializeSuccess(function (merchant) {12 //Merchant initialized successfully13 })14 .onMerchantInitializeFailure(function (err) {15 //Unable to intialize merchant - handle error scenario16 })17 .onPaymentSuccess(function (txnRecord) {18 //Payment success19 })20 .onPaymentFailure(function (err) {21 //Payment failed - handle error scenario22 });2324 var reader = payment_config.reader();25 reader.connectionType(pphwebsdk.Types.ReaderConnectionType.USB);26 reader.manufacturer(pphwebsdk.Types.Manufacturers.MIURA);2728 var order = pphwebsdk.Order.create();29 order.item('Cake').price(1.00).quantity(3);30 order.item('Coffee').price(2.00).quantity(3);31 order.tip(1.00);3233 var payment = pphwebsdk.Payment.create(identity, payment_config);34 payment.for(order).as(pphwebsdk.Types.PaymentMethod.CARD).sale();
Refund
1var identity = pphwebsdk.Identity.create(access_token).refreshUrl(refresh_url).environment(environment);23 var payment_config = pphwebsdk.PaymentConfiguration.create();4 payment_config.subscribe5 .onRefundSuccess(function (txnRecord) {6 //Payment success7 })8 .onRefundFailure(function (err) {9 //Payment failed - handle error scenario10 });1112 var reader = payment_config.reader();13 reader.connectionType(pphwebsdk.Types.ReaderConnectionType.USB);14 reader.manufacturer(pphwebsdk.Types.Manufacturers.MIURA);1516 var order = pphwebsdk.Order.create().on(txnId).with(ppInvoiceId).for(totalAmount);1718 var payment = pphwebsdk.Payment.create(identity, payment_config);19 payment.for(order).as(pphwebsdk.Types.PaymentMethod.CARD).refund();
When your integration is complete, check the going live page to ensure that you have everything ready for activation. Once that is working, you can implement other customizations that are available with the SDK into your integration.