Example usage for com.google.gson GsonBuilder excludeFieldsWithoutExposeAnnotation

List of usage examples for com.google.gson GsonBuilder excludeFieldsWithoutExposeAnnotation

Introduction

In this page you can find the example usage for com.google.gson GsonBuilder excludeFieldsWithoutExposeAnnotation.

Prototype

public GsonBuilder excludeFieldsWithoutExposeAnnotation() 

Source Link

Document

Configures Gson to exclude all fields from consideration for serialization or deserialization that do not have the com.google.gson.annotations.Expose annotation.

Usage

From source file:com.paysafe.PaysafeApiClient.java

License:Open Source License

/**
 * Take a domain object, and json serialize it.
 *
 * @param request the request//from   ww  w. j  av a  2 s  .c om
 * @param returnType the return type
 * @return json encoding of the request object
 */
private String serializeObject(Request request, Class<?> returnType) {
    final GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.excludeFieldsWithoutExposeAnnotation();
    gsonBuilder.registerTypeHierarchyAdapter(AddressContainer.class, new AddressContainerAdapter());
    gsonBuilder.registerTypeHierarchyAdapter(Id.class, new IdAdapter());
    if (null != request.getSerializer()) {
        gsonBuilder.registerTypeAdapter(returnType, request.getSerializer());
    }
    final Gson gson = gsonBuilder.create();
    return gson.toJson(request.getBody());
}

From source file:com.paysafe.websample.CustomerVaultACHBank.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the CustomerVault Service
    //Initialize the PaysafeApiClient 
    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    Purchases purchasesResponse = null;/*from w  ww  .j  ava  2  s  .  c  o m*/
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {

        Profile profile = Profile.builder().merchantCustomerId(java.util.UUID.randomUUID().toString())
                .locale(Locale.EN_US).firstName("John").lastName("Smith").email("john.smith@somedomain.com")
                .phone("713-444-5555").build();

        Profile profileRes = apiClient.customerVaultService().create(profile);

        Address address = Address.builder().nickName("home").street("100 Queen Street West").street2("Unit 201")
                .city("Toronto").country("CA").state("ON").zip("M5H 2N2").recipientName("Jane Doe")
                .phone("647-788-3901").profileId(profileRes.getId()).build();

        Address addressRes = apiClient.customerVaultService().create(address);

        ACHBankAccounts achBankAccounts = ACHBankAccounts.builder().nickName(request.getParameter("nickName"))
                .accountNumber(request.getParameter("accountNumber"))
                .routingNumber(request.getParameter("routingNumber"))
                .accountHolderName(request.getParameter("accountHolderName"))
                .billingAddressId(addressRes.getId()).accountType(AccountType.CHECKING)
                .profileId(profileRes.getId()).build();

        ACHBankAccounts achBankAccountsRes = apiClient.customerVaultService().create(achBankAccounts);

        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(achBankAccountsRes));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("purchases", purchasesResponse);

    // Create a new CustomerVault request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("CustomerVaultACHBank.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.CustomerVaultBACSBank.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the CustomerVault Service
    //Initialize the PaysafeApiClient 

    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    Purchases purchasesResponse = null;/* ww  w  .ja  v  a 2  s  .  co m*/
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {

        Profile profile = Profile.builder().merchantCustomerId(java.util.UUID.randomUUID().toString())
                .locale(Locale.EN_US).firstName("John").lastName("Smith").email("john.smith@somedomain.com")
                .phone("713-444-5555").build();

        Profile profileRes = apiClient.customerVaultService().create(profile);

        Address address = Address.builder().nickName("home").street("100 Queen Street West").street2("Unit 201")
                .city("Toronto").country("CA").state("ON").zip("M5H 2N2").recipientName("Jane Doe")
                .phone("647-788-3901").profileId(profileRes.getId()).build();

        Address addressRes = apiClient.customerVaultService().create(address);

        BACSBankAccounts bacsBankAccounts = BACSBankAccounts.builder()
                .nickName(request.getParameter("nickName")).sortCode(request.getParameter("sortCode"))
                .accountNumber(request.getParameter("accountNumber"))
                .accountHolderName(request.getParameter("accountHolderName"))
                .billingAddressId(addressRes.getId()).profileId(profileRes.getId()).build();

        BACSBankAccounts bacsBankAccountsRes = apiClient.customerVaultService().create(bacsBankAccounts);

        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(bacsBankAccountsRes));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("purchases", purchasesResponse);

    // Create a new CustomerVault request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("CustomerVaultBACSBank.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.CustomerVaultEFTBank.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the CustomerVault Service
    //Initialize the PaysafeApiClient 

    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    Purchases purchasesResponse = null;//from w  w w .  jav  a  2 s. c  o  m
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {

        Profile profile = Profile.builder().merchantCustomerId(java.util.UUID.randomUUID().toString())
                .locale(Locale.EN_US).firstName("John").lastName("Smith").email("john.smith@somedomain.com")
                .phone("713-444-5555").build();

        Profile profileRes = apiClient.customerVaultService().create(profile);

        Address address = Address.builder().nickName("home").street("100 Queen Street West").street2("Unit 201")
                .city("Toronto").country("CA").state("ON").zip("M5H 2N2").recipientName("Jane Doe")
                .phone("647-788-3901").profileId(profileRes.getId()).build();

        Address addressRes = apiClient.customerVaultService().create(address);

        EFTBankAccounts eftBankAccounts = EFTBankAccounts.builder().nickName(request.getParameter("nickName"))
                .accountNumber(request.getParameter("accountNumber"))
                .transitNumber(request.getParameter("transitNumber"))
                .accountHolderName(request.getParameter("accountHolderName"))
                .institutionId(request.getParameter("institutionId")).billingAddressId(addressRes.getId())
                .profileId(profileRes.getId()).build();

        EFTBankAccounts eftBankAccountsRes = apiClient.customerVaultService().create(eftBankAccounts);

        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(eftBankAccountsRes));
        //out.println("-----"+purchasesResponse.getMerchantRefNum());

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("purchases", purchasesResponse);

    // Create a new CustomerVault request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("CustomerVaultEFTBank.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.CustomerVaultMandates.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the CustomerVault Service
    //Initialize the PaysafeApiClient 
    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    String radio = request.getParameter("account");
    if (radio.equals("sepa")) {
        PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
                this.accountNumber);
        try {//ww w.j  a  va 2s  .  c  o m

            out.println("sepa selected");

            Profile profile = Profile.builder().merchantCustomerId(java.util.UUID.randomUUID().toString())
                    .locale(Locale.EN_US).firstName("John").lastName("Smith").email("john.smith@somedomain.com")
                    .phone("713-444-5555").build();

            Profile profileRes = apiClient.customerVaultService().create(profile);

            Address address = Address.builder().nickName("home").street("100 Queen Street West")
                    .street2("Unit 201").city("Toronto").country("CA").state("ON").zip("M5H 2N2")
                    .recipientName("Jane Doe").phone("647-788-3901").profileId(profileRes.getId()).build();

            Address addressRes = apiClient.customerVaultService().create(address);

            SEPABankAccounts sepaBankAccounts = SEPABankAccounts.builder()
                    .nickName("John RBC Business Bank Account").accountHolderName("XYZ Business")
                    .bic("PSPBFIHH").iban(request.getParameter("iban")).billingAddressId(addressRes.getId())
                    .profileId(profileRes.getId()).build();

            SEPABankAccounts sepaBankAccountsRes = apiClient.customerVaultService().create(sepaBankAccounts);

            Mandates mandates = Mandates.builder().reference(request.getParameter("reference"))
                    .profileId(profileRes.getId()).bankAccountId(sepaBankAccountsRes.getId().toString())
                    .build();

            Mandates mandatesRes = apiClient.customerVaultService().create(mandates, "SEPA");

            final GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.excludeFieldsWithoutExposeAnnotation();
            final Gson gson = gsonBuilder.create();
            out.println("response" + gson.toJson(mandatesRes));

            wasSuccessfull = true;

        } catch (PaysafeException e) {
            // TODO Auto-generated catch block
            request.setAttribute("error", e.getMessage());
            out.println(e.getMessage());
        }

        // Create a new customerVault request
        request.setAttribute("isPost", "true");
        request.setAttribute("currency", this.currencyCode);

        if (wasSuccessfull) {
            RequestDispatcher view = request.getRequestDispatcher("status.jsp");
            view.forward(request, response);
        } else {
            RequestDispatcher view = request.getRequestDispatcher("CustomerVaultSEPABank.jsp");
            view.forward(request, response);
        }
    } else {
        PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
                "1001057660");
        try {

            Profile profile = Profile.builder().merchantCustomerId(java.util.UUID.randomUUID().toString())
                    .locale(Locale.EN_US).firstName("John").lastName("Smith").email("john.smith@somedomain.com")
                    .phone("713-444-5555").build();

            Profile profileRes = apiClient.customerVaultService().create(profile);

            Address address = Address.builder().nickName("home").street("100 Queen Street West")
                    .street2("Unit 201").city("Toronto").country("CA").state("ON").zip("M5H 2N2")
                    .recipientName("Jane Doe").phone("647-788-3901").profileId(profileRes.getId()).build();

            Address addressRes = apiClient.customerVaultService().create(address);

            BACSBankAccounts bacsBankAccounts = BACSBankAccounts.builder()
                    .nickName("Sally's Bank of Montreal Account").accountNumber(sixDigitRandomNumber())
                    .accountHolderName("Sally").sortCode("070246").billingAddressId(addressRes.getId())
                    .profileId(profileRes.getId()).build();

            BACSBankAccounts bacsBankAccountsRes = apiClient.customerVaultService().create(bacsBankAccounts);

            Mandates mandates = Mandates.builder().reference(request.getParameter("reference"))
                    .profileId(profileRes.getId()).bankAccountId(bacsBankAccountsRes.getId().toString())
                    .build();

            Mandates mandatesRes = apiClient.customerVaultService().create(mandates, "BACS");

            final GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.excludeFieldsWithoutExposeAnnotation();
            final Gson gson = gsonBuilder.create();
            out.println("response" + gson.toJson(mandatesRes));

            wasSuccessfull = true;

        } catch (PaysafeException e) {
            // TODO Auto-generated catch block
            request.setAttribute("error", e.getMessage());
            out.println(e.getMessage());
        }

        // Create a new CustomerVault request
        request.setAttribute("isPost", "true");
        request.setAttribute("currency", this.currencyCode);

        if (wasSuccessfull) {
            RequestDispatcher view = request.getRequestDispatcher("status.jsp");
            view.forward(request, response);
        } else {
            RequestDispatcher view = request.getRequestDispatcher("CustomerVaultBACSBank.jsp");
            view.forward(request, response);
        }
    }

}

From source file:com.paysafe.websample.CustomerVaultSEPABank.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the CustomerVault Service
    //Initialize the PaysafeApiClient 

    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    Purchases purchasesResponse = null;//from w w w  .  ja  v a  2 s. c  o  m
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {

        Profile profile = Profile.builder().merchantCustomerId(java.util.UUID.randomUUID().toString())
                .locale(Locale.EN_US).firstName("John").lastName("Smith").email("john.smith@somedomain.com")
                .phone("713-444-5555").build();

        Profile profileRes = apiClient.customerVaultService().create(profile);

        Address address = Address.builder().nickName("home").street("100 Queen Street West").street2("Unit 201")
                .city("Toronto").country("CA").state("ON").zip("M5H 2N2").recipientName("Jane Doe")
                .phone("647-788-3901").profileId(profileRes.getId()).build();

        Address addressRes = apiClient.customerVaultService().create(address);

        SEPABankAccounts sepaBankAccounts = SEPABankAccounts.builder()
                .nickName(request.getParameter("nickName")).iban(request.getParameter("iban"))
                .bic(request.getParameter("bic")).accountHolderName(request.getParameter("accountHolderName"))
                .billingAddressId(addressRes.getId()).profileId(profileRes.getId()).build();

        SEPABankAccounts sepaBankAccountsRes = apiClient.customerVaultService().create(sepaBankAccounts);

        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(sepaBankAccountsRes));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("purchases", purchasesResponse);

    // Create a new CustomerVault request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("CustomerVaultSEPABank.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.DirectDebitACHPurchase.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the DirectDebit Purchase Service
    //Initialize the PaysafeApiClient 

    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    Purchases purchasesResponse = null;//from  w  w w. j  av a2  s .  co m
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {

        Purchases purchases = Purchases.builder()

                .merchantRefNum(request.getParameter("merchantRefNum"))
                .amount(Integer.parseInt(request.getParameter("amount"))).ach()
                .accountHolderName(request.getParameter("accountHolderName")).accountType(AccountType.CHECKING)
                .accountNumber(request.getParameter("accountNumber"))
                .routingNumber(request.getParameter("routingNumber")).payMethod(PayMethod.WEB).done()
                .customerIp(request.getParameter("customerIp")).profile()
                .firstName(request.getParameter("firstName")).lastName(request.getParameter("lastName"))
                .email(request.getParameter("email")).done().billingDetails()
                .street(request.getParameter("street")).city(request.getParameter("city"))
                .state(request.getParameter("state")).country(request.getParameter("country"))
                .zip(request.getParameter("zip")).phone(request.getParameter("phone")).done().build();

        purchasesResponse = apiClient.directDebitService().submitPurchase(purchases);
        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(purchasesResponse));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("purchases", purchasesResponse);

    // Create a new diredtdebit request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("directDebitACHPurchase.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.DirectDebitACHStandaloneCredit.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the DirectDebit StandaloneCredit Service
    //Initialize the PaysafeApiClient 
    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    StandaloneCredits standaloneCreditsResponse = null;
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {/*from   ww w.ja  v  a 2  s. c  o  m*/

        StandaloneCredits standaloneCredits = StandaloneCredits.builder()

                .merchantRefNum(request.getParameter("merchantRefNum"))
                .amount(Integer.parseInt(request.getParameter("amount"))).ach()
                .accountHolderName(request.getParameter("accountHolderName")).accountType(AccountType.CHECKING)
                .accountNumber(request.getParameter("accountNumber"))
                .routingNumber(request.getParameter("routingNumber")).payMethod(PayMethod.WEB).done()
                .customerIp(request.getParameter("customerIp")).profile()
                .firstName(request.getParameter("firstName")).lastName(request.getParameter("lastName"))
                .email(request.getParameter("email")).done().billingDetails()
                .street(request.getParameter("street")).city(request.getParameter("city"))
                .state(request.getParameter("state")).country(request.getParameter("country"))
                .zip(request.getParameter("zip")).phone(request.getParameter("phone")).done().build();

        standaloneCreditsResponse = apiClient.directDebitService().submitStandaloneCredit(standaloneCredits);
        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(standaloneCreditsResponse));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("standaloneCredits", standaloneCreditsResponse);

    // Create a new diredtdebit request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("directDebitACHStandaloneCredit.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.DirectDebitEFTPurchase.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the DirectDebit Purchase Service
    //Initialize the PaysafeApiClient 
    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    Purchases purchasesResponse = null;/*from  w w w . ja  v  a2 s . c  om*/
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {

        Purchases purchases = Purchases.builder()

                .merchantRefNum(request.getParameter("merchantRefNum"))
                .amount(Integer.parseInt(request.getParameter("amount"))).eft()
                .accountHolderName(request.getParameter("accountHolderName"))
                .accountNumber(request.getParameter("accountNumber"))
                .institutionId(request.getParameter("institutionId"))
                .transitNumber(request.getParameter("transitNumber")).done()
                .customerIp(request.getParameter("customerIp")).profile()
                .firstName(request.getParameter("firstName")).lastName(request.getParameter("lastName"))
                .email(request.getParameter("email")).done().billingDetails()
                .street(request.getParameter("street")).city(request.getParameter("city"))
                .state(request.getParameter("state")).country(request.getParameter("country"))
                .zip(request.getParameter("zip")).phone(request.getParameter("phone")).done().build();

        purchasesResponse = apiClient.directDebitService().submitPurchase(purchases);
        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(purchasesResponse));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
        out.println(e.getMessage());
    }

    request.setAttribute("purchases", purchasesResponse);

    // Create a new diredtdebit request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("directDebitEFTPurchase.jsp");
        view.forward(request, response);
    }

}

From source file:com.paysafe.websample.DirectDebitEFTStandaloneCredit.java

License:Open Source License

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // Initiate a new instance of the DirectDebit StandaloneCredit Service
    //Initialize the PaysafeApiClient 
    PrintWriter out = response.getWriter();
    boolean wasSuccessfull = false;
    StandaloneCredits standaloneCreditsResponse = null;
    PaysafeApiClient apiClient = new PaysafeApiClient(this.apiKey, this.apiPassword, Environment.TEST,
            this.accountNumber);
    try {/*from w w  w. j  av a2 s .co m*/

        StandaloneCredits standaloneCredits = StandaloneCredits.builder()

                .merchantRefNum(request.getParameter("merchantRefNum"))
                .amount(Integer.parseInt(request.getParameter("amount"))).eft()
                .accountHolderName(request.getParameter("accountHolderName"))
                .accountNumber(request.getParameter("accountNumber"))
                .institutionId(request.getParameter("institutionId"))
                .transitNumber(request.getParameter("transitNumber")).done()
                .customerIp(request.getParameter("customerIp")).profile()
                .firstName(request.getParameter("firstName")).lastName(request.getParameter("lastName"))
                .email(request.getParameter("email")).done().billingDetails()
                .street(request.getParameter("street")).city(request.getParameter("city"))
                .state(request.getParameter("state")).country(request.getParameter("country"))
                .zip(request.getParameter("zip")).phone(request.getParameter("phone")).done().build();

        standaloneCreditsResponse = apiClient.directDebitService().submitStandaloneCredit(standaloneCredits);
        final GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        final Gson gson = gsonBuilder.create();

        out.println("response" + gson.toJson(standaloneCreditsResponse));

        wasSuccessfull = true;

    } catch (PaysafeException e) {
        // TODO Auto-generated catch block
        request.setAttribute("error", e.getMessage());
    }

    request.setAttribute("standaloneCredits", standaloneCreditsResponse);

    // Create a new diredtdebit request
    request.setAttribute("isPost", "true");
    request.setAttribute("currency", this.currencyCode);

    if (wasSuccessfull) {
        RequestDispatcher view = request.getRequestDispatcher("status.jsp");
        view.forward(request, response);
    } else {
        RequestDispatcher view = request.getRequestDispatcher("directDebitEFTStandaloneCredit.jsp");
        view.forward(request, response);
    }

}