Android Native Integration

Step 1: Create order from your server.

Sandbox Endpoint: https://sandbox.gokwik.co/v1/order/create

Request Data:

Header

NameTagsDescription
AppidMandatory StringYOUR APPID is different for test and production
AppsecretMandatory StringYOUR APPSECRET is different for test and production
Content-TypeMandatory StringApplication/json

Body

SL no.ObjectParameterTypeDescription
1orderidMandatory Stringorder id which will be unique for all future communication as moid. if you have only cart id then you can send cart id in "id" as well as in "cart_id"
2ordercart_idOptional String
3orderstatusMandatory StringPending would be first order status
4ordersubtotalMandatory Float (2 digits after decimal)total cart value before applying discount
5ordertotal_line_itemsMandatoryInteger number of unique sku's in the order
6ordertotal_line_items_quantityMandatoryInteger total number of items
7ordertotal_tax MandatoryFloat (2 digits after decimal)total calculated tax
8ordertotal_shippingMandatoryFloat (2 digits after decimal)total shipping charges
9ordertotal_discount MandatoryFloat (2 digits after decimal)total discount amount on order value
10ordertotal MandatoryFloat (2 digits after decimal) total = subtotal + total_tax + total_shipping - total_discount(discount due to promocode or cashback discount )
11orderpromo_codeMandatory Stringpromo code applied
12ordersourceMandatory StringExample: organic/facebook/instagram/others
13ordercustomer_ipMandatory StringExample: "103.82.80.57"
14ordercustomer_user_agentMandatory StringExample : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:86.0) Gecko/20100101 Firefox/86.0"
15payment_detailsmethod_idMandatory Stringeither "upi" or "cod" both in small case
16line_itemsproduct_idVarchar id of the product, which is used to list the product on the store
17line_itemsline_item_idVarchar line_item id which type of product
18line_itemsvariant_idVarchar variation if for the product
19line_itemsnameStringname of the product
20line_itemsskuMandatory Stringsku of the product
21line_itemspriceMandatory Float (2 digits after decimal)maximum retail price of that product
22line_itemsquantityMandatory Integerquantity of the product
23line_itemssubtotalFloat (2 digits after decimal)Sale price of the products in this line item
24line_itemstotalMandatory Float (2 digits after decimal)total of all the products in line_item after discount, tax and shipping
25line_itemstaxFloat (2 digits after decimal)calculated value for tax
26line_itemsproduct_url Stringurl of the product page
27line_itemsproduct_thumbnail_urlStringurl of the thumbnail image of the product
28productany fieldJsonObjecthere you need to add product more details like colour, size, etc..
29shipping_addressfirst_nameMandatory Stringfirst name of user
30shipping_addresslast_nameMandatory Stringlast name of user
31shipping_addresscompanyStringcompany name of user
32shipping_addressaddress_1Mandatory Stringaddress line 1
33shipping_addressaddress_2Stringaddress line 2
34shipping_addresscityOptional Stringdelivery city
35shipping_addressstateMandatory Stringdelivery state
36shipping_addresspostcodeMandatory Stringdelivery postcode
37shipping_addressemailStringemail id of user
38shipping_addressphoneVarchar Limit10phone number of user
39billing_addressfirst_nameMandatory Stringfirst name of user
40billing_addresslast_nameStringlast name of user
41billing_addresscompanyStringcompany name of user
42billing_addressaddress_1Mandatory Stringaddress line 1
43billing_addressaddress_2Stringaddress line 2
44billing_addresscityMandatory Stringaddress city
45billing_addressstateMandatory Stringaddress state
46billing_addresspostcodeMandatory Stringaddress postcode
47billing_addressemailStringemail id of user
48billing_addressphoneVarchar limit10phone number of user
COUNT 48
Curl Example:
Copy
curl --location --request POST 'https://sandbox.gokwik.co/v1/order/create' --header 'appid: YOUR APPID' --header 'appsecret: YOUR APPSECRET' --header 'content-type: application/json' --data-raw '{
    "order": {
        ^"id": "240", (string)
        ^"cart_id": "240", (string)
        "status": "pending",(string)
        *"subtotal": "800", //total sale price of line items (string)
        *"total_line_items": "1", (string)
        *"total_line_items_quantity": "1", (string)
        *"total_tax": "160", //tax for entire order (string) 
        *"total_shipping": "50.0", //shipping charges (string)
        *"total_discount": "100", //promo_code related discount or cashback discount (string)
        *"total": "910", // total = subtotal + total_tax + total_shipping - total_discount(discount due to promocode or cashback discount )(string)
        *"promo_code":"XYZ_20",(string)
        *"source":"organic", //"organic/facebook/instagram/others"(string)+
        *"payment_details": {
            *"method_id": "upi/cod"
        },
        *"billing_address": {
            *"first_name": "Test",
            *"last_name": "Shop",
            "company": "Test",
            *"address_1": "Test",
            "address_2": "",
            *"city": "Delhi",
            *"state": "DL",
            *"postcode": "110092",
            *"country": "IN",
            "email": "xyz@exampal.com",
            "phone": "99XXXXXX99" // 10 digit phone number
        },
        *"shipping_address": {
            *"first_name": "",
            *"last_name": "",
            "company": "",
            *"address_1": "",
            "address_2": "",
            *"city": "",
            *"state": "",
            *"postcode": "",
            *"country": "",
            "email": "xyz@exampal.com",
            "phone": "99XXXXXX99" // 10 digit phone number
        },
        *"customer_ip": "103.82.80.57",
        *"customer_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:86.0) Gecko/20100101 Firefox/86.0",
        *"line_items": [{
            *"product_id": "15",
            "line_item_id" : "id_of_line_item", //can be set as "", this is the sub-order id of an order can have all items as same line_item_id if they have same awb 
            *"variant_id": "0",  // this should be uniq acorss all products.
            "product": {},
            *"name": "Beanie",
            *"sku": "",
            *"price": 1000, //MRP 
            *"quantity": 1,
            "subtotal": "800", // Sale price
            *"total": "800",
            "tax": "0",//
            "awb_number":"", // for initition you can send it blank
            "shipping_provider":"",
            *"product_url": "",
            *"product_thumbnail_url": ""
        }]
    }

Response:

Copy
{
"statusCode": 200,
"statusMessage": "Placed",
"data": {
    "request_id": "95421d15-c62d-90c64-9673-ee6d37e35374",
    "gokwik_oid": "KWIKOIO8WXO6013589",
    "order_status": "Pending",
    "total": "36.00",
    "moid": "245",
    "mid": "sample_id_by_gokwik",
    "phone": "9876543210",
    "order_type": "upi"
}
}
Copy
{
  "statusCode": 201,
  "statusMessage": "Order already exist!"
}
Copy
{
  "statusCode": 404,
  "statusMessage": "Merchant not registered!"
}
Copy
{
  "statusCode": 400,
  "statusMessage": "Order Failed"
}
Copy
{
  "statusCode": 500,
  "statusMessage": "Oops!! Something went wrong"
}

Note:

Either cart_id or moid must be present when placing the order

Step 2: Add Gokwik sdk module in your project

Download the GoKwik SDK from here and add it to the app's libs folder.

Step 3: Add gradle dependencies

Add lines in app level build.gradle
Copy
implementation files('libs/gokwik_sdk_1_0.aar')
implementation "com.squareup.retrofit2:retrofit:$retrofit"
implementation "com.squareup.retrofit2:converter-gson:$retrofit"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit"
Enable databinding
Copy
android {
    buildFeatures {
        dataBinding true
    }
}

Step 4: Open Gokwik app for payment from your activity when customer click on payment button.

Copy
JSONObject option = new JSONObject();
option.put("request_id", request_id);
option.put("gokwik_oid", gokwik_oid);
option.put("total", total);
option.put("moid",moid);
option.put("mid", mid);
option.put("phone", phone);
option.put("order_type", order_type);
Checkout.getInstance().open(SampleActivity.this<Activity Context>, option<JSON File>, false<Production==True, Test ==false>);

Note:

You will get all the parameters mentioned above it in step 1's response when you create order

Step 5: Register call back for payment success and failure

implement your activity with GoKwikPaymentListner

You will get 2 callbacks:
Copy
@Override
public void onPaymentSuccess(JSONObject response) {
    Toast.makeText(this, "Payment Success and response: " + response.toString(), Toast.LENGTH_LONG).show();
}

@Override
public void onPaymentError(String error) {
    Toast.makeText(this, "Payment Fail: " + error, Toast.LENGTH_LONG).show();

}

Note:

In onPaymentSuccess() you will get all information related to transection and In onPaymentError() you will get error happen during the payment.

BASE URL: base URL for test and production environment

Test Server: https://sandbox.gokwik.co

Production Server: https://api.gokwik.co

Other important info:

appid: YOUR APPID.

appsecret: YOUR APPSECRET

Above two things you need to send in order create API that you will get once you register with GoKwik.