Passa al contenuto principale
In questa pagina

Questa guida copre come integrare Apple Pay direttamente con l'API di DEUNA. L'integrazione diretta consente di controllare il flusso di pagamento, rendendolo ideale per i commercianti che hanno bisogno di implementazioni personalizzate o di sistemi di pagamento esistenti. Questa integrazione supporta i pagamenti a tempo parziale.


Paga di mele con DEUNA#

Di seguito è il processo standard per un acquisto Apple Pay con DEUNA:

  1. Ottieni i metodi di pagamento
  2. Inizializzare il Web SDK di Apple Pay
  3. Acquistare con Apple Pay

1. Ottenere i metodi di pagamento#

Recuperare i parametri di configurazione di Apple Pay e ID di configurazione SDK.

→ Vedi Ottieni i metodi di pagamento API di riferimento

Restituisce l’ordine elaborato con

JSON
{
  "data": [
    {
      "allow_installments_plan": true,
      "credentials": {
        "external_merchant_id": "merchant.test.io.deuna.pay"
      },
      "enabled": true,
      "extra_params": {
        "allowed_auth_methods": [
          "supports3DS"
        ],
        "allowed_card_networks": [
          "visa",
          "masterCard",
          "amex"
        ],
        "merchant_name": "Test DEUNA"
      },
      "id": "ef2319fe-f88d-4d8d-b4d1-e4fa08f18651",
      "method_type": "card_wallet",
      "payment_provider": "apple_pay",
      "processor_name": "apple_pay"
    }
  ]

2. Inizializzare il Web SDK di Paga di Apple#

Fare riferimento al Documentazione SDK Web di Apple Pay per il riferimento completo.

Importare il JS di Apple Pay SDK

Aggiungi il seguente script alla tua pagina:

HTML
<script src="https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js" crossorigin=""></script>
HTML
<script src="https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js" crossorigin=""></script>

Esempio di integrazione completo

JavaScript
// 1. Check availability
if (!window.ApplePaySession || !ApplePaySession.canMakePayments()) {
  // Apple Pay not available — hide the button or show a fallback
}

// 2. Initialize the session on button click (must be inside a user gesture)
// Use the values returned by the Get Payment Methods endpoint
const request = {
  countryCode: 'MX',
  currencyCode: 'MXN',
  supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'], // from extra_params.allowed_card_networks
  merchantCapabilities: ['supports3DS'],                          // from extra_params.allowed_auth_methods
  total: { label: 'Your Store Name', amount: '1.00', type: 'final' },
};

const session = new ApplePaySession(3, request);

// 3. Validate the merchant
// The credential-id comes from the `id` field in the Get Payment Methods response
session.onvalidatemerchant = async (event) => {
  const response = await fetch(
    'https://api.{env}.deuna.io/wallet/credentials/{credential-id}/payment-session',
    {
      method: 'POST',
      headers: {
        'X-Merchant-Id': '{merchant-id}',
        'X-Store-Code': '{store-code}',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        validation_url: event.validationURL,
        domain: '{your-domain}',
      }),
    }
  );

  const { data } = await response.json();
  session.completeMerchantValidation(data);
};

// 4. Handle payment authorization
// Once the customer authorizes the payment, send the token to DEUNA
// Use applePayToken in step 3 — Create Card or Purchase V2
session.onpaymentauthorized = (event) => {
  const applePayToken = event.payment;

  session.completePayment(ApplePaySession.STATUS_SUCCESS);
};

session.begin();

3. Acquistare con Apple Pay#

Una volta che il cliente autorizza il pagamento sul proprio dispositivo Apple, onpaymentauthorized incendi evento e consegna un gettone di carta crittografato tramite event.payment. Questo token deve essere inviato come-è, senza alcuna modifica, a DEUNA.

3.1 Creare la carta

Il segno da event.payment viene inviato al punto finale Crea carta, che restituisce un card_id che può essere riutilizzato nell'acquisto.

→ Visualizzare Creare API di riferimento

JSON
{
  "apple_pay": {
    "paymentData": {
      "token": {
        "transactionIdentifier": "7a94479858348...",
        "paymentMethod": {
          "type": "debit",
          "displayName": "Visa 7553",
          "network": "Visa"
        },
        "paymentData": {
          "data": "EOeLQTsv8X7f...",
          "header": {
            "publicKeyHash": "MpXcCgm...",
            "ephemeralPublicKey": "MFkwEwYH...",
            "transactionId": "7a94479858348..."
          },
          "version": "EC_v1"
        }
      }
    }
  },
  "credential_source": "apple_pay"
}

3.2 Purchase with Card ID

Utilizzare questa opzione quando la scheda è già stata tokenizzata tramite Create Card. Questa è una richiesta standard di acquisto V2 utilizzando card_id restituito dal punto di vista della carta Creata — nessun token di pagamento Apple necessario.

→ Vedi Acquisto V2 API riferimento

JSON
{
  "order_token": "{order-token}",
  "order_type": "DEUNA_CHECKOUT",
  "payer_info": {
    "email": "customer@example.com",
    "card_holder_dni": "12345678"
  },
  "payment_source": {
    "method_type": "credit_card",
    "card_info": {
      "card_id": "{deuna-card-id}"
    }
  }
}

3.3 Acquisto diretto

Questo è per i casi che la carta non è tokenized. Il segno da event.payment viene inviato direttamente nella richiesta di acquisto.

→ Vedi Acquisto V2 API riferimento

JSON
{
    "order_token": "{{order-token}}",
    "order_type": "DEUNA_CHECKOUT",
    "payer_info": {
        "email": "{{random_user}}@testuser.com",
        "card_holder_dni": "12345678"
    },
    "payment_source": {
        "method_type": "credit_card",
        "card_info": {
            "credential_source": "apple_pay",
            "credential_source_config": {
                "type": "apple_pay",
                "values": {
                    "system": "EC_v1",
                    "merchant_transaction_id": "6bfbf33f787b7932d5d0....",
                    "encrypted_data": "Fk11fwjWL3uFZlBwAw83G0xRt8....",
                    "encryption_header": {
                        "signature": "MIAGCSqGSIb3DQEHAqCAMIACAQEx...",
                        "public_key_hash": "EB8/SypLvJCISa2d4sQzV/Zw...",
                        "ephemeral_public_key": "MFkwEwYHKoZIzj0CAQYIKoZIzj..."
                    }
                }
            }
        }
    },
    "anti_fraud_info": {
        "device": {
            "id": "eyJPUEVOUEFZIjoiIiwiTUVSQ0FET1BBzAzLTk2NjRkYzE3MWQzYiJ9..."
        }
    }
}

Restituisce l’ordine elaborato con

JSON
{
  "order_type": "DEUNA_CHECKOUT",
  "order_token": "4598f493-de86-4fe0-b9fd-c4c6c9847e39",
  "order": {
    "order_id": "DEUNA_CHECKOUT_b6a5c0b6-3df9-4b3b-b778-7086c190062b",
    "currency": "MXN",
    "total_amount": 10000,
    "display_total_amount": "MXN 100,00",
    "status": "succeeded",
    "payment": {
      "data": {
        "status": "processed"
      }
    }
  }
}