Skip to content

Latest commit

 

History

History
145 lines (102 loc) · 8.82 KB

payment-flows.md

File metadata and controls

145 lines (102 loc) · 8.82 KB
description
Understand the flow of a transaction through Hyperswitch

🌊 Payment flows

{% hint style="info" %} This chapter will cover the payment flows available with Hyperswitch. Please reach out to us to learn more about the payment flows supported! {% endhint %}

Payments flow

There are multiple stages in a Payment flow depending on the payment methods that are involved. Considering an one-time payment method where there was no redirection involved, the following stages form the Payment flow:

a) Creating a Payment: When your customer wants to checkout, create a payment by hitting the payments/create endpoint. Fetch and store the payment_id and client_secret

b) Loading the SDK: After your customer checks out, load the Hyperswitch SDK by initiating it with the client_secret and publishable_key

c) SDK being rendered: After you initiate the SDK, the SDK makes several API calls involving the /sessions and /payment_methods endpoints to load relevant payment methods and any saved cards associated with the customer

d) Customer enters the payment method data: After the SDK is fully rendered, your customer would choose a payment method and enter the relevant information and click pay

e) Confirming the payment: After the customer clicks pay, the SDK calls the payments/confirm endpoint with the customer's payment method details and post response, it displays the payment status

Here's a more detailed version of the payment flow:

How does Payment flow vary across Payment methods?

Customer ActionDirect/Redirect flowsPayment- finalized immediatelyPayment- finalized later
Customer action required before payments/ confirmWithin Hyperswitch SDK
  • Non 3DS Cards
  • Bank Debits like ACH Debit, BACS Debit, SEPA Debit
Customer action required before payments/ confirm3rd party Redirect/SDK
  • Wallets like Apple Pay, Google pay, Paypal, AliPay
  • BNPL like Klarna, Afterpay, Affirm

Customer action required after payments/ confirm3rd party Redirect
  • 3DS cards
  • Bank Redirects like iDeal, Giropay, eps
  • Bank Transfers like ACH Transfer, SEPA Transfer, BACS Transfer, Multibanco
  • Crypto wallets like Cryptopay

Use-cases supported by Hyperswitch

Accept online paymentsGet started with accepting one time payments globally on your online storeonlinePayments.jpgquickstart
Setup mandates & recurring paymentsSetup payments for a future date or charge your customers on a recurring basisrecurringPayments.jpgmandates-and-recurring-payments.md
Manage payoutsFacilitate payouts for global network of partners and service providersPayment flow (1) (1).jpgpayouts
Save a card during paymentLearn how you can save your customers' cards in a secure PCI compliant mannersaveCard.jpgtokenization-and-saved-cards.md
Manage payments on your platform / marketplaceAccept payments from your customers and process payouts to the sellers on your marketplacemarketplace.jpgmultiple-accounts-and-profiles.md
Accept payments on your e-commerce platformGive your Wordpress store a lightweight and embedded payment experience with the Hyperswitch WooCommerce pluginWooComerce.jpgwoocommerce-plugin
Create payment links Accept payments for your products through reusable links without writing any codepaymentLinks.jpgpayment-links.md

What are PaymentIntent and PaymentAttempt objects and how do they work in Hyperswitch?

Hyperswitch uses the PaymentIntent object to track the status of a payment initiated by you. Since, Hyperswitch enables retrying a single payment multiple times across different processors until a successful transaction, we track each of these payment attempts through separate PaymentAttempt objects.

While PaymentIntent and PaymentAttempt have their own state machines, the various states in PaymentAttempt are also constrained by their respective mapping to the PaymentIntent statuses.


PaymentIntent state machine:

The following is an abridged version of the PaymentIntent state machine flow that covers majority of the above payment use-cases.

%%{
  init: {
    'theme': 'forest',
    'themeVariables': {
      'fontSize': '14px',
      'background': '#17202A'
}
  }
}%%

flowchart TD

A{PaymentsAPI} --> |amount,currency|RequiresPaymentMethod
    RequiresPaymentMethod -->|payment_method| RequiresConfirmation
    RequiresConfirmation --> |confirm| Processing
    Processing --> AuthType{auth type\nselection}
    AuthType --> |3ds| RequiresCustomerAction
    AuthType --> |no-3ds| CaptureMethod{capture method\nselection}

    CaptureMethod --> |manual| RequiresCapture
    CaptureMethod --> |automatic| Succeeded
    RequiresCustomerAction --> CustomerAction{customer_action\nresult}
    CustomerAction -->|success| CaptureMethod
    CustomerAction -->|failure| Failed

    RequiresCapture --> |capture|Succeeded
 

PaymentAttempt state machine:

The following is an abridged version of the PaymentAttempt state machine flow that covers majority of the above payment use-cases.

%%{
  init: {
    'theme': 'forest',
    'themeVariables': {
      'fontSize': '16px',
      'background': '#17202A'
}
  }
}%%


flowchart TD

    AuthenticationFailed
    AuthenticationPending
    AuthenticationSuccessful
    Authorized
    AuthorizationFailed
    Charged
    Voided
    CaptureInitiated
    CaptureFailed
    Pending
    PaymentMethodAwaited
    ConfirmationAwaited
    DeviceDataCollectionPending

    A{PaymentsAPI} --> |amount,currency|PaymentMethodAwaited
    PaymentMethodAwaited -->|payment_method| ConfirmationAwaited
    ConfirmationAwaited --> |confirm| Pending

    %% Before calling the connector change status to Pending
    Pending --> CallConnector{CallConnector}
    CallConnector -->|Success| AuthType{auth_type}
    CallConnector -->|Fail| AuthorizationFailed
    AuthType --> |no-3ds| CaptureMethod{capture_method} 
    AuthType --> |3ds| DeviceDataCollectionPending
    DeviceDataCollectionPending --> |CollectDeviceData|AuthenticationPending --> Authenticate{Authenticate}
    Authenticate --> |Success| AuthenticationSuccessful --> CaptureMethod{capture method}
    Authenticate --> |Failure| AuthenticationFailed
    
    %% Capture
    CaptureMethod --> |automatic| Charged
    CaptureMethod --> |manual| Authorized

    Authorized --> |capture| CaptureInitiated --> Capture{Capture at connector}
    Capture -->|Success| Charged
    Capture -->|Failed| CaptureFailed

    %% Payment can be voided after calling the connector but not charged
    %% This will not void the payment at connector
    DeviceDataCollectionPending -->|void| Voided
    AuthenticationPending -->|void| Voided

    %% Voiding a payment after it is Authorized will void at connector
    Authorized -->|void|Voided