Send Payment Status

Sending Status

Once payment has been completed, you should inform us if the payment was successful. This is important to provide better analytics in identifying top areas of failure points. Payment status can be one of: SUCCESS, FAILURE or CANCELLED.

Among all the three following techniques, sending the status from the server is the most reliable as the network between servers is much more robust.

From endUrlReached function

Since we always invoke callback method for all payment completions, you could send us the payment status at that point.

// Putting payment status
[self.browser startpaymentWithJuspayInView:self.view withParameters:parms callback:^(BOOL status, NSError *error, id info) {

    TransactionStatus *transactionStatus = [[TransactionStatus alloc] init];
    if (status) {
        NSDictionary *data = (NSDictionary*)info;
        NSString *endURL = [data objectForKey:kENDURL];

        if (endURL.length) {
            if ([endURL containsString:@"<sucess value present>"]) {
                transactionStatus.paymentID = kTRANSACTIONID;
                transactionStatus.paymentStatus = SUCCESS;
            }else if ([endURL containsString:@"<failure value present>"]){
                transactionStatus.paymentID = kTRANSACTIONID;
                transactionStatus.paymentStatus = FAILURE;
            }
        }
    }else{
        transactionStatus.paymentID = kTRANSACTIONID;
        if (error.code==JSCancelledByUser) {
            transactionStatus.paymentStatus = CANCELLED;
        }else{
            transactionStatus.paymentStatus = UNKNOWNSTATUS;
        }
    }
    [Logger logPaymentStatus:transactionStatus];
}];
// Putting payment status
self.browser.startpaymentWithJuspayInView(self.view, withParameters: browserParams) { (status:Bool, error:NSError!, info:AnyObject!) in
        let transactionStatus = TransactionStatus()
        if (status) {
            let data = info as! NSDictionary;
            let endURL = data.objectForKey("EndUrl") as! String;
            if (endURL.containsString("<sucess value present>")) {
                transactionStatus.paymentID = "TransactionID";
                transactionStatus.paymentStatus = SUCCESS;
            }else if (endURL.containsString("<failure value present>")){
                transactionStatus.paymentID = "TransactionID";
                transactionStatus.paymentStatus = FAILURE;
            }
        }else{
            transactionStatus.paymentID = "TransactionID";
            if (error.code==101) {
                transactionStatus.paymentStatus = CANCELLED;
            }else{
                transactionStatus.paymentStatus = UNKNOWNSTATUS;
            }
        }
        JPLoger.sharedInstance().logPaymentStatus(transactionStatus)
}

However, it may not always be possible to have the payment status at this point, especially if the aggregator uses HTTP POST for sending the payment details. In such cases, you can POST the status from your server.

From your Server

Payment status can also be sent from your servers. Please make sure that the following parameters are sent correctly along with the status:

  • client_id
  • merchant_id
  • order_id
  • transaction_id

Data must be sent as a properly formatted JSON. Example payload:

{
  "data":[
    {
      "merchant_id":"shop",
      "client_id":"shop_ios",
      "order_id":"ord_112233",
      "transaction_id":"txn_112233",
      "payment_status":"SUCCESS"
    }
  ]
}

Payment status can be one of: SUCCESS, FAILURE or CANCELLED. Example HTTP POST to send payment status is provided below:

# Post status directly to Juspay server
curl https://logs.juspay.in/godel/analytics \
  -H 'Content-Type: application/json' \
  -d '{"data":[{"merchant_id":"shop", "client_id":"shop_ios", "order_id":"ord_112233", "transaction_id": "txn_112233", "payment_status":"SUCCESS"}]}'

Note: This is the preferred method for sending Status to JusPay. Please send if Failure also. Otherwise, the transactions will be categorized as unknown.