src/test/java/com/squareup/connect/api/TransactionsApiTest.java
@Test
    public void chargeTest() throws ApiException {
        // Check different sandbox values here https://docs.connect.squareup.com/articles/using-sandbox

        String idempotencyKey = UUID.randomUUID().toString();
        ChargeRequest body = new ChargeRequest()
            .idempotencyKey(idempotencyKey)
            .amountMoney(new Money()
                .amount(200L)
                .currency("USD"))
            .cardNonce(cardNonce)
            .shippingAddress(new Address()
                .addressLine1("123 Main St")
                .locality("San Francisco")
                .administrativeDistrictLevel1("CA")
                .postalCode("94114")
                .country("US"))
            .billingAddress(new Address()
                .addressLine1("500 Electric Ave")
                .addressLine2("Suite 600")
                .administrativeDistrictLevel1("NY")
                .locality("New York")
                .postalCode("10003")
                .country("US"))
            .referenceId("optional reference #112358")
            .note("optional note");

        ChargeResponse response = api.charge(locationId, body);

        assertTrue(response.getErrors().isEmpty());
        assertNotNull(response.getTransaction().getId());
    }
/**
     * Charge
     *
     * Charges a card represented by a card nonce or a customer&#39;s card on file.  Your request to this endpoint must include _either_:  - A value for the &#x60;card_nonce&#x60; parameter (to charge a card nonce generated with the &#x60;SqPaymentForm&#x60;) - Values for the &#x60;customer_card_id&#x60; and &#x60;customer_id&#x60; parameters (to charge a customer&#39;s card on file)  In order for an e-commerce payment to potentially qualify for [Square chargeback protection](https://squareup.com/help/article/5394), you _must_ provide values for the following parameters in your request:  - &#x60;buyer_email_address&#x60; - At least one of &#x60;billing_address&#x60; or &#x60;shipping_address&#x60;  When this response is returned, the amount of Square&#39;s processing fee might not yet be calculated. To obtain the processing fee, wait about ten seconds and call [RetrieveTransaction](#endpoint-retrievetransaction). See the &#x60;processing_fee_money&#x60; field of each [Tender included](#type-tender) in the transaction.
     *
     * @throws ApiException
     *          if the Api call fails
     */
Charge
Charges a card represented by a card nonce or a customer's card on file.

@throws ApiException
if the Api call fails
Charge Charges a card represented by a card nonce or a customer ' s card on file . @throws ApiException if the Api call fails
@Test
    public void chargeTest() throws ApiException {
        String idempotencyKey = UUID.randomUUID().toString();
        ChargeRequest body = new ChargeRequest()
            .idempotencyKey(idempotencyKey)
            .amountMoney(new Money()
                .amount(200L)
                .currency("USD"))
            .cardNonce(cardNonce)
            .shippingAddress(new Address()
                .addressLine1("123 Main St")
                .locality("San Francisco")
                .administrativeDistrictLevel1("CA")
                .postalCode("94114")
                .country("US"))
            .billingAddress(new Address()
                .addressLine1("500 Electric Ave")
                .addressLine2("Suite 600")
                .administrativeDistrictLevel1("NY")
                .locality("New York")
                .postalCode("10003")
                .country("US"))
            .referenceId("optional reference #112358")
            .note("optional note");
        ChargeResponse response = api.charge(locationId, body);
        assertTrue(response.getErrors().isEmpty());
        assertNotNull(response.getTransaction().getId());
    }
@ Test public void chargeTest ( ) throws ApiException { String idempotencyKey = UUID . randomUUID ( ) . toString ( ) ; ChargeRequest body = new ChargeRequest ( ) . idempotencyKey ( idempotencyKey ) . amountMoney ( new Money ( ) . amount ( 200L ) . currency ( "USD" ) ) . cardNonce ( cardNonce ) . shippingAddress ( new Address ( ) . addressLine1 ( "123 Main St" ) . locality ( "San Francisco" ) . administrativeDistrictLevel1 ( "CA" ) . postalCode ( "94114" ) . country ( "US" ) ) . billingAddress ( new Address ( ) . addressLine1 ( "500 Electric Ave" ) . addressLine2 ( "Suite 600" ) . administrativeDistrictLevel1 ( "NY" ) . locality ( "New York" ) . postalCode ( "10003" ) . country ( "US" ) ) . referenceId ( "optional reference #112358" ) . note ( "optional note" ) ; ChargeResponse response = api . charge ( locationId , body ) ; assertTrue ( response . getErrors ( ) . isEmpty ( ) ) ; assertNotNull ( response . getTransaction ( ) . getId ( ) ) ; }
Charge
 Charges a card represented by a card nonce or a customer&#39;s card on file.
Charge Charges a card represented by a card nonce or a customer&#39 ; s card on file .
// Check different sandbox values here https://docs.connect.squareup.com/articles/using-sandbox