PlexySDK DOCS

Test Tokenization

Test saving and reusing payment methods

Test Tokenization

Test storing payment methods for repeat customers.

Save a payment method

// Create a customer
const customer = await plexy.customers.create({
  email: 'test@example.com',
  name: 'Test Customer'
});

// Attach a payment method
const paymentMethod = await plexy.paymentMethods.create({
  type: 'card',
  card: {
    number: '4242424242424242',
    exp_month: 12,
    exp_year: 2030,
    cvc: '123'
  }
});

await plexy.paymentMethods.attach(paymentMethod.id, {
  customer: customer.id
});

Charge a saved payment method

const payment = await plexy.payments.create({
  amount: 5000,
  currency: 'USD',
  customer: customer.id,
  payment_method: paymentMethod.id,
  off_session: true
});

Test card update scenarios

Simulate card updates (e.g., new expiry date):

Card NumberScenario
4000002500001001Card will be updated
4000002760001001Card update fails

Test recurring payments

// First payment with setup
const firstPayment = await plexy.payments.create({
  amount: 5000,
  currency: 'USD',
  payment_method: { /* card details */ },
  setup_future_usage: 'off_session'
});

// Subsequent payments
const recurringPayment = await plexy.payments.create({
  amount: 5000,
  currency: 'USD',
  customer: 'cus_abc123',
  payment_method: firstPayment.payment_method,
  off_session: true
});

Verify token storage

After saving, verify the token:

  1. List customer's payment methods
  2. Check card fingerprint matches
  3. Verify last4 and brand are correct
const methods = await plexy.paymentMethods.list({
  customer: customer.id,
  type: 'card'
});

console.log(methods.data[0].card.last4); // '4242'
console.log(methods.data[0].card.brand); // 'visa'

See also

На этой странице