- Include 3D Secure as part of your integration.
- Pass the cardholder's billing address as part of the transaction processing.
Integrate 3D Secure using Card Fields
Last updated: May 13th, 9:44am
Enable 3D Secure for advanced credit and debit cards. This integration uses the JavaScript SDK.
If you have a standard checkout integration, you don't need to integrate 3D Secure. PayPal handles 3D secure authentication for standard checkout integrations.
Important: These 3D Secure instructions apply to the JavaScript SDK component CardFields
. If your integration uses the HostedFields
component, see Integrate 3D Secure using Hosted Fields instead.
Know before you code
RequiredIf you are based in Europe, you may be subject to PSD2:
Update the advanced card fields code
To trigger the authentication, pass the verification method in the create order payload. The verification method can be a contingencies parameter with SCA_ALWAYS
or SCA_WHEN_REQUIRED
.
SCA_ALWAYS
triggers an authentication for every transaction, while SCA_WHEN_REQUIRED
triggers an authentication only when a regional compliance mandate such as PSD2 is required. 3D Secure is supported only in countries with a PSD2 compliance mandate.
1// Create the CardFields component and define callbacks and contingencies2const cardField = paypal.CardFields({3 createOrder: function(data) {4 return fetch("myserver.com/api/paypal/order/create/", {5 method: "post",6 body: JSON.stringify({7 ...89 payment_source: { // wrap 3D Secure preference in `payment_source`10 card: {11 attributes: {12 verification: {13 method: "SCA_ALWAYS"14 },15 },16 experience_context: {17 shipping_preference: "NO_SHIPPING",18 return_url: "https://example.com/returnUrl",19 cancel_url: "https://example.com/cancelUrl",20 },21 },22 }23 }).then((res) => {24 return res.json();25 }).then((orderData) => {26 return orderData.id;27 });28 }, )29 },30 onApprove: function(data) {31 const {32 liabilityShift,33 orderID34 } = data;35 if (liabilityShift) {36 /* Handle liability shift. More information in 3D Secure response parameters */37 }38 return fetch('myserver.com/api/paypal/orders/${orderID}/capture/', {39 method: "post",40 }).then((res) => {41 return res.json();42 }).then((orderData) => {43 // Redirect to a success page44 });45 },46 onError: function(error) {47 // Do something with the error from the SDK48 }49});50// Render each field after checking for eligibility51if (cardField.isEligible()) {52 const nameField = cardField.NameField();53 nameField.render('#card-name-field-container');54 const numberField = cardField.NumberField();55 numberField.render('#card-number-field-container');56 const cvvField = cardField.CVVField();57 cvvField.render('#card-cvv-field-container');58 const expiryField = cardField.ExpiryField();59 expiryField.render('#card-expiry-field-container');60 // Add a click listener to submit button and call the submit function on the CardField component61 document.getElementById("multi-card-field-button").addEventListener("click", () => {62 cardField.submit().then(() => {63 // Submit is successful64 });65 });66}