---
page_title: 5. Making a Payment
product: EC Headless
platform: Android
page_source: https://juspay.io/in/docs/ec-headless/android/base-sdk-integration/making-a-payment
llms_txt: https://juspay.io/in/docs/llms.txt
product_llms_txt: https://juspay.io/in/docs/ec-headless/llms.txt
---


## 5. Making a Payment



Once the checkout page is rendered, your users may proceed with payments. Payment initiation has two steps to it:

1. [Order Creation](https://docs.juspay.in/ec-headless/android/base-sdk-integration/making-a-payment#5.1.-Order-Creation)
2. [Transaction Initiation](https://docs.juspay.in/ec-headless/android/base-sdk-integration/making-a-payment#5.2.-Transaction-Initiation)

Following sections describe how to complete the steps above -


### 5.1. Order Creation



Create an order that is a representation of your shopping cart. The order contains important information like amount, customer details, shipping address, billing address, etc. Only after an order is created at Juspay end, the payment can be initiated.To create an order follow the step below -


### Step 5.1.a. Call Create Order API


Call [Create Order API](/ec-headless/android/base-sdk-integration/create-order-api) to create an order_id at Juspay end and get the corresponding client_auth_token

> **Warning**
> client_auth_token is valid only for 15 mins and is used for frontend authentication of SDK/client side calls.






### 5.2. Transaction Initiation



Transaction initiation involves a `process` SDK call from the merchant application with a process payload based on the payment method selected by your user. To inititate a transaction, follow the steps below -


### Step 5.2.a. Process SDK Call for Transaction Initiation


A process SDK call is to be made with a process payload based on the payment method selected by the user. For sample request and response payloads for different process SDK calls, please refer to the [payload samples](https://docs.juspay.in/ec-headless/android/payloads/displaying-payment-options) page and use the dropdown menus to select the appropriate category and flows.

> **Warning**
> Process SDK call is to be made on the same instance of HyperService using which initiate API was triggered. It should not be called on an HyperSDK instance which has not been initiated.





#### Code Snippets: -

#### Java Code Snippet:

```java
if (hyperInstance.isInitialised()){
    hyperInstance.process(processPayload);
}
```



### Step 5.2.b. Consume Process SDK Response


Upon receiving the process call, the SDK internally initiates a transaction request to Juspay servers. Process response is returned as an SDK callback to the merchant application post payment completion.



---

## Complete Code Reference

The following code files are referenced in the steps above:

### CheckoutActivity.java

```

{
    //block:start:process-sdk-call

    if (hyperInstance.isInitialised()){
    hyperInstance.process(processPayload);
}
    //block:end:process-sdk-call



    // block:start:create-hyper-callback
    
    private HyperPaymentsCallbackAdapter createHyperPaymentsCallbackAdapter() {
        return new HyperPaymentsCallbackAdapter() {
            @Override
            public void onEvent(JSONObject jsonObject, JuspayResponseHandler responseHandler) {
                Intent redirect = new Intent(CheckoutActivity.this, ResponsePage.class);
                redirect.putExtra("responsePayload", jsonObject.toString());
                System.out.println(jsonObject);
                try {
                    String event = jsonObject.getString("event");
                    if (event.equals("hide_loader")) {
                        // Hide Loader
                        dialog.hide();
                    }
                    else if (event.equals("initiate_result")) {
                        boolean error = jsonObject.optBoolean("error");
                        JSONObject innerPayload = jsonObject.optJSONObject("payload");
                        String status = innerPayload.optString("status");
                        if (status.equals("success")) {
                            // Initiate was successful, handle accordingly (call Process)
                        } else {
                            // Initiate failed, handle accordingly (call initiate() again)
                        }
                    }
                    // Handle Process Result
                    // This case will reach once the Hypercheckout screen closes
                    // block:start:handle-process-result
                    else if (event.equals("process_result")) {
                        boolean error = jsonObject.optBoolean("error");
                        JSONObject innerPayload = jsonObject.optJSONObject("payload");
                        String status = innerPayload.optString("status");

                        if (!error) {
                            switch (status) {
                                case "charged":
                                    // Successful Transaction
                                    // check order status via S2S API
                                    redirect.putExtra("status", "OrderSuccess");
                                    startActivity(redirect);
                                    break;
                                case "cod_initiated":
                                    redirect.putExtra("status", "CODInitiated");
                                    startActivity(redirect);
                                    break;
                            }
                        } else {
                            switch (status) {
                                case "backpressed":
                                    // user back-pressed from PP without initiating transaction

                                    break;
                                case "user_aborted":
                                    // user initiated a txn and pressed back
                                    // check order status via S2S API
                                    Intent successIntent = new Intent(CheckoutActivity.this, ResponsePage.class);
                                    redirect.putExtra("status", "UserAborted");
                                    startActivity(redirect);
                                    break;
                                case "pending_vbv":
                                    redirect.putExtra("status", "PendingVBV");
                                    startActivity(redirect);
                                    break;
                                case "authorizing":
                                    // txn in pending state
                                    // check order status via S2S API
                                    redirect.putExtra("status", "Authorizing");
                                    startActivity(redirect);
                                    break;
                                case "authorization_failed":
                                    redirect.putExtra("status", "AuthorizationFailed");
                                    startActivity(redirect);
                                    break;
                                case "authentication_failed":
                                    redirect.putExtra("status", "AuthenticationFailed");
                                    startActivity(redirect);
                                    break;
                                case "api_failure":
                                    redirect.putExtra("status", "APIFailure");
                                    startActivity(redirect);
                                    break;
                                    // txn failed
                                    // check order status via S2S API
                            }
                        }
                    }
                    // block:end:handle-process-result
                } catch (Exception e) {
                    // merchant code...
                }
            }
        };
    }
    // block:end:create-hyper-callback



    //block:start:onBackPressed
    
    @Override
    public void onBackPressed() {
        boolean handleBackpress = hyperServicesHolder.onBackPressed();
        if(!handleBackpress) {
            super.onBackPressed();
        }

    }
    //block:end:onBackPressed

    

    /*
    Optional Block
    These functions are only supposed to be implemented in case if you are overriding
    onActivityResult or onRequestPermissionsResult Life cycle hooks


    - onActivityResult
    - Handling onActivityResult hook and passing data to HyperServices Instance, to handle App Switch
    @Override
    public void onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        // block:start:onActivityResult

        // If super.onActivityResult is available use following:
        // super.onActivityResult(requestCode, resultCode, data);

        // In case super.onActivityResult is NOT available please use following:
        // if (data != null) {
        //    hyperServices.onActivityResult(requestCode, resultCode, data);
        // }

        // block:end:onActivityResult

        // Rest of your code.
    }


    - onRequestPermissionsResult
    - Handling onRequestPermissionsResult hook and passing data to HyperServices Instance, to OTP reading permissions
    @Override
    public void onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        // block:start:onRequestPermissionsResult

        //  If super.onRequestPermissionsResult is available use following:
        // super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // In case super.onActivityResult is NOT available please use following:
        // hyperServices.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // block:end:onRequestPermissionsResult
    }
     */
}

```


---

## See Also

- [4. Rendering the Checkout Screen](https://juspay.io/in/docs/ec-headless/android/base-sdk-integration/rendering-the-checkout-screen)
- [6. Handling Payment Response](https://juspay.io/in/docs/ec-headless/android/base-sdk-integration/handling-payment-response)
