[SalesForce] Chargent AppFrontier – Unexpected character (‘S’ (code 83))

I am trying to integrate salesforce with Chargent with Stripe gateway and custome Chargent Order Object. I have a requirement to make changes in the VF Page so i have created the VF page and according to the documentation here("https://www.appfrontier.com/developers.html") i am calling the webservice method ChargentOrders.TChargentOperations.ChargeOrder_Click. But when i call the method from VF page it is showing the Error.

Unexpected character ('S' (code 83)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
Error is in expression '{!charge}' in component <apex:commandButton> in page chargentwithstripe: Class.System.JSON.deserializeUntyped: line 11, column 1
Class.ChargentBase.Payment_Stripe.GetResponseItem: line 457, column 1
Class.ChargentBase.Payment_Stripe.common_CC_AuthorizeAndCharge: line 163, column 1
Class.ChargentBase.Payment_Stripe.AuthorizeAndCharge: line 71, column 1
Class.ChargentBase.TPayment.AuthorizeAndCharge: line 391, column 1
Class.ChargentBase.TPayment.ExecuteTransaction: line 63, column 1
Class.ChargentBase.ChargentWebService.ProcessWeb: line 172, column 1
Class.ChargentBase.TChargentOperations.AuthorizeAndCharge: line 2367, column 1
Class.ChargentBase.TChargentOperations.ChargeBody: line 1956, column 1
Class.ChargentBase.TChargentOperations.ChargeOpportunity_Click: line 803, column 1
Class.ChargentOrders.TChargentOperations.ChargeOrder_Click: line 52, column 1
Class.ChargentWithStripe_Ctrl.charge: line 114, column 1

The code of the Controller is :-

public void charge() {
    if(obj != NULL) {
        obj.ChargentOrders__Card_Number__c = cardNumber;
        obj.ChargentOrders__Card_Security_Code__c = securityCode;
        obj.ChargentOrders__Card_Expiration_Month__c = expMonth;
        obj.ChargentOrders__Card_Expiration_Year__c = '2020';//For Testing
        System.debug(LoggingLevel.ERROR, '-->>cardNumber='+cardNumber);
        System.debug(LoggingLevel.ERROR, '-->>securityCode='+securityCode);
        System.debug(LoggingLevel.ERROR, '-->>expMonth='+expMonth);
        System.debug(LoggingLevel.ERROR, '-->>expYear='+expYear);
        update obj;
        System.debug(LoggingLevel.ERROR, '-->>obj='+obj);
        ChargentOrders.TChargentOperations.TChargentResult ChargentResult = ChargentOrders.TChargentOperations.ChargeOrder_Click(obj.Id); //This is the Line 114
        System.debug(LoggingLevel.ERROR, '-->>ChargentResult='+ChargentResult.Message);
    }
}

This is the Object I am getting from the Debug:

-->>cardNumber=4012888888881881
-->>securityCode=123
-->>expMonth=09
-->>expYear=22
-->>obj=ChargentOrders__ChargentOrder__c:{Id=a052800000BNtN4AAL, ChargentOrders__Billing_State__c=California, ChargentOrders__Billing_First_Name__c=Akshay, ChargentOrders__Billing_Last_Name__c=Dhiman, ChargentOrders__Billing_Address__c=1 County Government Education Prog, ChargentOrders__Billing_City__c=Pleasant Hill, ChargentOrders__Billing_Zip_Postal__c=94523, ChargentOrders__Billing_Country__c=United States, ChargentOrders__Billing_Email__c=akshay@gmail.com, ChargentOrders__Subtotal__c=123432.00, ChargentOrders__Billing_Address_Line_2__c=, ChargentOrders__Card_Number__c=************1881, ChargentOrders__Card_Security_Code__c=***, ChargentOrders__Card_Expiration_Month__c=**, ChargentOrders__Card_Expiration_Year__c=****}

NOTE:- However there is some strange things happening do not know how. When i run the Method in Execute anonymous like this:-

ChargentOrders.TChargentOperations.ChargeOrder_Click('a052800000BNtN4');

Everything works fine and the Transaction gets created so there is no problem with the record. Same goes for the Custom Button on the chargent Order Object. I have also tried by hard coding the Id as i did in Execute Anonymous but getting the same error again.

Please help me.
Thank you.

Best Answer

Not a direct answer but an answer nonetheless:

  1. In the end you are calling the same method to process the Chargent Order

    ChargentOrders.TChargentOperations.ChargeOrder_Click(obj.Id)

This means that if it works in the Dev Console that the state of your Opportunity is such that it is able to be charged and Stripe produces an expected response

  1. Since in your VF page you are setting value on the Chargent Order and then calling the exact same method, this points to something you are setting on the Chargent Order not being quite right.

Some possible reasons:

  1. Card number is invalid and causes stripe to return a webpage instead of a deserializable response. 1b. Having the test mode checked (or running in a sandbox) and using a real card number could cause this
  2. Using a test card number in non test mode

Chargent expects Stripe to respond with a deserializable DOM with name/value pairs that deserializes into a Map<String,Object> and a response of type HTML (404, or other error) coould cause this.

So, AppFrontier is best suited to help you through this. It is ultimately an issue with how you have coded you VF page and the values you are setting.

We could go back and forth here but would need more code to provide a definite answer.