package com.ripple.cli;

import com.ripple.client.Account;
import com.ripple.client.Client;
import com.ripple.client.ClientLogger;
import com.ripple.client.Response;
import com.ripple.client.blobvault.BlobVault;
import com.ripple.client.transactions.Transaction;
import com.ripple.client.transactions.TransactionManager;
import com.ripple.client.transactions.TransactionMessage.TransactionResult;
import com.ripple.client.transport.impl.JavaWebSocketTransportImpl;
import com.ripple.core.types.AccountID;
import com.ripple.core.types.Amount;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import static com.ripple.cli.log.Log.LOG;

public class MakePayment {
    public static void main(String[] args) throws Exception {
        ClientLogger.quiet = false;
        makeAPayment();
    }

    private static void makeAPayment() throws IOException, InvalidCipherTextException, JSONException, InterruptedException {
        Client client = new Client(new JavaWebSocketTransportImpl());
        client.connect("wss://s1.ripple.com");
        BlobVault blobVault = new BlobVault("https://blobvault.payward.com/");
        JSONObject blob = blobVault.getBlob("niq1", "");
        Account account = client.accountFromSeed(blob.getString("master_seed"));
        makePayment(account, "rP1coskQzayaQ9geMdJgAV5f3tNZcHghzH", "1");
    }

    private static void makePayment(Account account, Object destination, String amt) {
        TransactionManager tm = account.transactionManager();
        Transaction        tx = tm.payment();

        tx.put(AccountID.Destination, destination);
        tx.put(Amount.Amount, amt);

        tx.once(Transaction.OnSubmitSuccess.class, new Transaction.OnSubmitSuccess() {
            @Override
            public void called(Response response) {
                LOG("Submit response: %s", response.engineResult());
            }
        });
        tx.once(Transaction.OnTransactionValidated.class, new Transaction.OnTransactionValidated() {
            @Override
            public void called(TransactionResult result) {
                LOG("Transaction finalized on ledger: %s", result.ledgerIndex);
                try {
                    LOG("Transaction message:\n%s", result.message.toString(4));
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }

            }
        });

        tm.queue(tx);
    }
}

@@ -753,16 +753,788 @@
 yment %7B%0A
+    /**%0A     * These refer to the blobs storing the contacts and wallet secret at payward%0A     * That is where the account information for the https://ripple.com/client%0A     * is by default stored.%0A     */%0A    public static String PAYWARD_USER = %22niq1%22;%0A    public static String PAYWARD_PASS = %22%22;%0A%0A    public static String DESTINATION_ACCOUNT = %22rP1coskQzayaQ9geMdJgAV5f3tNZcHghzH%22;%0A    public static String SEND_AMOUNT = %221%22; /* drop, or millionth of an XRP.%0A                                               Specify an amount with a decimal (eg. 1.0) to indicate XRPS%0A                                               Sadly %221%22 != %221.0%22 in ripple json string format%0A                                               Be aware :)%0A                                               */%0A
     publ
@@ -1771,32 +1771,181 @@
 ptedException %7B%0A
+        if (PAYWARD_USER.isEmpty() %7C%7C PAYWARD_PASS.isEmpty()) %7B%0A            LOG(%22Must configure PAYWARD_USER && PAYWARD_PASS%22);%0A        %7D else %7B%0A    
         Client c
@@ -2006,16 +2006,20 @@
         
+    
 client.c
@@ -2057,16 +2057,20 @@
         
+  
+  
 BlobVaul
@@ -2140,16 +2140,20 @@
         
+    
 JSONObje
@@ -2184,21 +2184,41 @@
 lob(
-%22niq1%22, %22%22);%0A
+PAYWARD_USER, PAYWARD_PASS);%0A    
     
@@ -2298,24 +2298,28 @@
 ));%0A        
+    
 makePayment(
@@ -2331,51 +2331,53 @@
 nt, 
-%22rP1coskQzayaQ9geMdJgAV5f3tNZcHghzH%22, %221%22);
+DESTINATION_ACCOUNT, SEND_AMOUNT);%0A        %7D%0A
 %0A   
@@ -2453,22 +2453,22 @@
 nation, 
-String
+Object
  amt) %7B%0A

Update MakePayment with clearer usage instructions