QuickBooks NULL CallbackHandler

QuickBooks NULL CallbackHandler

我正在尝试在 QuickBook 中执行批处理操作,但得到的回调处理程序为空。

private static void AddBulkCustomer(DataService ds) throws FMSException{

        BatchOperation bo = new BatchOperation();
        Customer c1 = new Customer();
        c1.setGivenName("Customer 3");
        c1.setDisplayName("Disp Customer 3");
        EmailAddress email = new EmailAddress();
        email.setAddress("customer1@zzz.com");
        c1.setPrimaryEmailAddr(email);

        bo.addEntity(c1, OperationEnum.CREATE, "b3");

        c1= null;
        c1 = new Customer();
        c1.setGivenName("Customer 4");
        c1.setDisplayName("Disp Customer 4");
        email = null;
        email = new EmailAddress();
        email.setAddress("customer2@z2zz.com");
        c1.setPrimaryEmailAddr(email);

        bo.addEntity(c1, OperationEnum.CREATE, "b4");

//      String strQuery = " select * from customer where givenname ='"+c1.getGivenName()+"'";
//      bo.addQuery(strQuery, "b3Query");

        ds.executeBatchAsync(bo, new AsyncCallBackBatch());
    }

对于 AsyncCallback 操作

public class AsyncCallBackBatch implements CallbackHandler {


    @Override
    public void execute(CallbackMessage callbackMsg) {
        System.out.println("asyncCallbackBatch is executing... ");
        try {
                System.out.println("QR = "+callbackMsg.getFMSException().toString());
                BatchOperation BO = callbackMsg.getBatchOperation();
                if (BO != null) {
                List<String> bId = BO.getBIds();
                for (String strBId : bId) {
                    if (BO.isFault(strBId)) {
                        Fault fault = BO.getFault(strBId);
                        System.out.println("asyncCallBackBatch Error Code : "+ fault.getError().get(0).getCode() + " "+ "Error : "
                                + fault.getError().get(0).getDetail()+ ", Message : "+ fault.getError().get(0).getMessage());
                    } else if (BO.isEntity(strBId)) {
                        System.out.println("Batch having entity message.. ");
                        Customer cust = (Customer) BO.getEntity(strBId);
                        System.out.println("cust id : " + cust.getId()+ " CustName = " + cust.getGivenName());
                    } else if (BO.isQuery(strBId)) {
                        System.out.println("Batch having Query ... Parsing...  ");
                        QueryResult qR = BO.getQueryResponse(strBId);
                        System.out.println("Query : " + qR.getTotalCount());
                    } else if (BO.isReport(strBId)) {
                        System.out.println("Batch having Report...  ");
                        Report report = BO.getReport(strBId);
                        System.out.println(" " + report.getClass().getName());
                    } else {
                        System.out.println("Something went wrong... ");
                    }
                }
            }else{
                System.out.println("Batch Operation terminated, reason: NULL callbackMsg ");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}


public static void main(String[] args) {
        OAuthAuthorizer oAuth = new OAuthAuthorizer(consumerKey, consumerSecret, accessToken, accessTokenSecret);

        //403352746

        try {

            Context context = new Context(oAuth, ServiceType.QBO, "403352746");
            System.out.println("RealmID : "+context.getRealmID());
            context.setCustomerRequestTimeout(99999);
            System.out.println("TimeOut Set to = "+context.getCustomerRequestTimeout());

            System.out.println("BASE_URL_QBO = "+Config.getProperty(Config.BASE_URL_QBO));
            Config.setProperty(Config.BASE_URL_QBO, "https://sandbox-quickbooks.api.intuit.com/v3/company");
            System.out.println("BASE_URL_QBO = "+Config.getProperty(Config.BASE_URL_QBO));
            DataService ds = new DataService(context);

            AddBulkCustomer(ds);
            System.out.println("Operation Complete..");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

当我调试时,在执行方法中,我在 return 中得到 Null BatchOperation。我不确定在沙箱环境中是否允许执行批处理操作。

经过大量测试并与 Quickbooks Devs 沟通后,我找到了解决方案,认为这对其他人有帮助。

在沙箱环境中,即使您将配置属性设置为沙箱 URL,它仍然会在 Callbackhandler 中选择为 PROD URL。

    Config.setProperty(Config.BASE_URL_QBO, "https://sandbox-quickbooks.api.intuit.com/v3/company");

在这种情况下,他们称这是一个错误,目前您所能做的就是在 PROD 中创建一个试用帐户,然后进行测试。