Getting Started

Sections

Pixel (Embedded)

Outcome: Integrate Paymob's pre-built UI (Pixel) in the merchant's checkout.


Pre-Requisites

  • Integrate the Intention API as described in the documentation for the Create Payment Intention API.
  • Include the following script and stylesheets in your HTML file
HTML

Usage

Create a new Pixel instance

JavaScript
new Pixel({
publicKey: 'egy_pk_live_XXXX', clientSecret: 'egy_csk_live_XXXX', paymentMethods: [ 'card','google-pay','apple-pay'], elementId: 'paymob-elements', disablePay: false, showSaveCard :true, forceSaveCard : true,
beforePaymentComplete: async (paymentMethod) => { console.log('Before payment start'); return true },
afterPaymentComplete: async (response) => { console.log('After Bannas payment'); },
onPaymentCancel: () => { console.log('Payment has been canceled'); },
cardValidationChanged: (isValid) => { console.log("Is valid ? ", isValid) },
customStyle: { Font_Family: 'Gotham', Font_Size_Label: '16', Font_Size_Input_Fields: '16', Font_Size_Payment_Button: '14', Font_Weight_Label: 400, Font_Weight_Input_Fields: 200, Font_Weight_Payment_Button: 600, Color_Container: '#FFF', Color_Border_Input_Fields: '#D0D5DD', Color_Border_Payment_Button: '#A1B8FF', Radius_Border: '8', Color_Disabled: '#A1B8FF', Color_Error: '#CC1142', Color_Primary: '#144DFF', Color_Input_Fields: '#FFF', Text_Color_For_Label: '#000', Text_Color_For_Payment_Button: '#FFF', Text_Color_For_Input_Fields: '#000', Color_For_Text_Placeholder: '#667085', Width_of_Container: '100%', Vertical_Padding: '40', Vertical_Spacing_between_components: '18', Container_Padding: '0' },
}); </script>

Note: If Google Pay is passed as a Payment Method, you must include the Google Pay SDK

<script src="https://pay.google.com/gp/p/js/pay.js"></script>

Google Pay isn't supported in Egypt yet; it's coming soon. Stay tuned.

Properties

The full list of properties is as follows:

Property name
Type
Definition

publicKey

String

To know how to get your public key, please check the Getting Integration Credentials page.

clientSecret

String

Once you fire the Intention API, you will receive “client_secret” in the API Response, which will be used in the Pixel SDK. Client Secret is unique for each Order, and it expires in an hour.

paymentMethods

Array of String

Pass “card” for Card Payments, "google-pay" for Google Pay, and “apple-pay” for Apple Pay.

elementId

String

ID of the HTML element where the checkout pixel will be embedded.

disablePay

Boolean

Pass true. If you don’t want to use Paymob’s Pay Button for Card Payment, in this case, you will dispatchEvent with the name (payFromOutside) to fire the pay.

showSaveCard

Boolean

If this option is set to TRUE, users will have the option to save their card details for future payment.

forceSaveCard

Boolean

If this option is set to true, the user's card details will be saved automatically without requiring their consent

afterPaymentComplete

Function

This Functionality will be processed after payment is processed by Paymob. Check the full example below.

customStyle

Object

You can pass custom styles; for more details, check the full example below.

Events

We have one event that will be used if you want to trigger the payment from a custom Pay button, not Pixel's Pay button:

Event

Definition

payFromOutside

In case you need to use you pay button instead of the SDK pay button.

HTML
JavaScript
const button = document.getElementById('payFromOutsideButton'); button?.addEventListener ('click', function () { // Calling pay request const event = new Event('payFromOutside'); window.dispatchEvent(event); });

Functions

The full list of functions is as follows:

Function
Definition
What should you do with?

cardValidationChanged

This Functionality will be processed whenever the card validation status changes.

Writes the function logic

beforePaymentComplete

Merchants can implement their own custom logic or functions before the payment is processed by Paymob. Check the full example below.

Writes the function logic

afterPaymentComplete

This Functionality will be processed after payment is processed by Paymob. Check the full example below.

Writes the function logic

onPaymentCancel

This function applies exclusively to Apple Pay. Merchants can implement their own custom logic to handle scenarios where a user cancels the Apple Pay payment by closing the Apple Pay SDK.

Writes the function logic

updateIntentionData

Update the intention data within the SDK if any changes occur to the intention. For more details, refer to the Intention Update API documentation.

Calls the function

Full sample

HTML
Was this section helpful?

What made this section unhelpful for you?

On this page
  • Pixel (Embedded)