List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject(String memberName)
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
License:Apache License
/** * Sell bitcoin and receive a credit to the user's U.S. bank account. * @param qty the number of bitcoins to sell * @return A Transfer object containing information about the sale. * @throws IOException/*from ww w. jav a2 s . c om*/ */ public Transfer sellBitcoin(float qty) throws IOException { Map<String, String> params = new HashMap<String, String>(); if (apiKey != null) params.put("api_key", apiKey); params.put("qty", Float.toString(qty)); params.put("agree_btc_amount_varies", Boolean.toString(true)); JsonObject response = RequestClient.post(this, "sells", params, accessToken); boolean success = response.get("success").getAsBoolean(); return success ? Transfer.fromJson(response.getAsJsonObject("transfer")) : null; }
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
License:Apache License
/** * Creates a new payment button, page, or iframe * @param name The name of the item for which you are collecting bitcoin. For example, Acme Order #123 or Annual Pledge Drive * @param amount Price as a decimal string, for example 1.23. Can be more then two significant digits if currency equals BTC. * @param currency Price currency as an ISO 4217 code such as USD or BTC. This determines what currency the price is shown in on the payment widget. * @param type One of buy_now, donation, and subscription. * @param style One of buy_now_large, buy_now_small, donation_large, donation_small, subscription_large, subscription_small, custom_large, custom_small, and none. none is used if you plan on triggering the payment modal yourself using your own button or link. * @param text Allows you to customize the button text on custom_large and custom_small styles. * @param desc Longer description of the item in case you want it added to the users transaction notes. * @param custom An optional custom parameter. Usually an Order, User, or Product ID corresponding to a record in your database. * @param callbackUrl A custom callback URL specific to this button. It will receive the same information that would otherwise be sent to your Instant Payment Notification URL. If you have an Instant Payment Notification URL set on your account, this will be called instead they will not both be called. * @param successUrl A custom success URL specific to this button. The user will be redirected to this URL after a successful payment. It will receive the same parameters that would otherwise be sent to the default success url set on the account. * @param cancelUrl A custom cancel URL specific to this button. The user will be redirected to this URL after a canceled order. It will receive the same parameters that would otherwise be sent to the default cancel url set on the account. * @param infoUrl A custom info URL specific to this button. Displayed to the user after a successful purchase for sharing. It will receive the same parameters that would otherwise be sent to the default info url set on the account. * @param isVariablePrice Allow users to change the price on the generated button. * @param includeAddress Collect shipping address from customer (not for use with inline iframes). * @param includeEmail Collect email address from customer (not for use with inline iframes). * @return Json response containing the button information * @throws IOException/*from w w w. ja va 2 s . c om*/ */ public JsonObject makeButton(String name, String amount, String currency, String type, String style, String text, String desc, String custom, String callbackUrl, String successUrl, String cancelUrl, String infoUrl, boolean isVariablePrice, boolean includeAddress, boolean includeEmail) throws IOException, UnsupportedRequestVerbException { JsonObject jsonRequest = createButtonRequestJson(name, type, amount, currency, style, text, desc, custom, callbackUrl, successUrl, cancelUrl, infoUrl, isVariablePrice, includeAddress, includeEmail); JsonObject resp = RequestClient.post(this, "buttons", jsonRequest, accessToken); return resp != null && resp.has("button") ? resp.getAsJsonObject("button") : null; }
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
License:Apache License
/** * Get details for an individual transaction. * @param transactionId the id of the transaction to retrieve * @return A Transaction object containing details for the transaction * @throws IOException//from w ww .java2 s .c o m */ public Transaction getTransaction(String transactionId) throws IOException { JsonObject response = RequestClient.get(this, "transactions/" + transactionId, accessToken); return Transaction.fromJson(response.getAsJsonObject("transaction")); }
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
License:Apache License
private Transaction sendMoney(String to, String amount, String amountString, String currency, String notes, String fee, String refererId) throws IOException { Map<String, String> params = new HashMap<String, String>(); if (apiKey != null) params.put("api_key", apiKey); params.put("transaction[to]", to); if (amount != null) params.put("transaction[amount]", amount); if (amountString != null) params.put("transaction[amount_string]", amountString); if (currency != null) params.put("transaction[amount_currency_iso]", currency); if (notes != null) params.put("transaction[notes]", notes); if (fee != null) params.put("transaction[user_fee]", fee); if (refererId != null) params.put("transaction[referrer_id]", refererId); JsonObject response = RequestClient.post(this, "transactions/send_money", params, accessToken); if (!response.get("success").getAsBoolean()) return null; return Transaction.fromJson(response.getAsJsonObject("transaction")); }
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
License:Apache License
private Transaction requestMoney(String from, String amount, String amountString, String currency, String notes) throws IOException { Map<String, String> params = new HashMap<String, String>(); if (apiKey != null) params.put("api_key", apiKey); params.put("transaction[from]", from); if (amount != null) params.put("transaction[amount]", amount); if (amountString != null) params.put("transaction[amount_string]", amountString); if (currency != null) params.put("transaction[amount_currency_iso]", currency); if (notes != null) params.put("transaction[notes]", notes); JsonObject response = RequestClient.post(this, "transactions/request_money", params, accessToken); if (!response.get("success").getAsBoolean()) return null; return Transaction.fromJson(response.getAsJsonObject("transaction")); }
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
License:Apache License
/** * Complete a money request./*from w ww . j av a 2 s . c o m*/ * @param requestId The id of the request transaction to complete * @return A Transaction object * @throws IOException */ public Transaction completeMoneyRequest(String requestId) throws IOException { Map<String, String> params = new HashMap<String, String>(); if (apiKey != null) params.put("api_key", apiKey); JsonObject response = RequestClient.put(this, "transactions/" + requestId + "/complete_request", params, accessToken); if (!response.get("success").getAsBoolean()) return null; return Transaction.fromJson(response.getAsJsonObject("transaction")); }
From source file:com.createtank.payments.coinbase.models.Transaction.java
License:Apache License
public static Transaction fromJson(JsonObject json) { String id = json.get("id").getAsString(); String createdAt = json.get("created_at").getAsString(); Amount amount = Amount.fromJson(json.getAsJsonObject("amount")); boolean request = json.get("request").getAsBoolean(); TransactionStatus status = TransactionStatus.valueOf(json.get("status").getAsString().toUpperCase()); User sender = User.fromJson(json.getAsJsonObject("sender")); return json.has("recipient_address") ? new Transaction(id, createdAt, amount, request, status, sender, json.get("recipient_address").getAsString()) : new Transaction(id, createdAt, amount, request, status, sender, User.fromJson(json.getAsJsonObject("recipient"))); }
From source file:com.createtank.payments.coinbase.models.Transfer.java
License:Apache License
public static Transfer fromJson(JsonObject json) { Map<String, Fee> fees = new HashMap<String, Fee>(); JsonObject feesJson = json.getAsJsonObject("fees"); fees.put("coinbase", Fee.fromJson(feesJson.getAsJsonObject("coinbase"))); fees.put("bank", Fee.fromJson(feesJson.getAsJsonObject("bank"))); return new Transfer(json.get("type").getAsString(), json.get("code").getAsString(), json.get("created_at").getAsString(), fees, json.get("payout_date").getAsString(), json.get("transaction_id").getAsString(), TransactionStatus.valueOf(json.get("status").getAsString().toUpperCase()), Amount.fromJson(json.getAsJsonObject("btc")), Amount.fromJson(json.getAsJsonObject("subtotal")), Amount.fromJson(json.getAsJsonObject("total")), json.get("description").getAsString()); }
From source file:com.createtank.payments.coinbase.models.User.java
License:Apache License
public static User fromJson(JsonObject json) { User user = new User(); user.setId(json.get("id").getAsString()); user.setEmail(json.get("email").getAsString()); user.setName(json.get("name").getAsString()); user.setTimezone(json.get("time_zone").getAsString()); user.setNativeCurrency(json.get("native_currency").getAsString()); user.setBuyLevel(json.get("buy_level").getAsInt()); user.setSellLevel(json.get("sell_level").getAsInt()); user.setBalance(Amount.fromJson(json.getAsJsonObject("balance"))); user.setBuyLimit(Amount.fromJson(json.getAsJsonObject("buy_limit"))); user.setSellLimit(Amount.fromJson(json.getAsJsonObject("sell_limit"))); return user;//from w w w. j a v a2 s.c om }
From source file:com.cybozu.kintone.database.JsonParser.java
License:Apache License
/** * Reads and parses each comment element. * @param elem//from w ww .j a v a 2s . c om * a json element represents a comment object * @return the comment object created * @throws IOException */ private Comment readComment(JsonElement elem) throws IOException { Comment comment = null; Gson gson = new Gson(); if (elem.isJsonObject()) { JsonObject obj = elem.getAsJsonObject(); long id = obj.get("id").getAsLong(); String text = obj.get("text").getAsString(); Date createdAt = getDateTime(obj.get("createdAt").getAsString()); Type userElementType = new TypeToken<UserDto>() { }.getType(); UserDto user = gson.fromJson(obj.getAsJsonObject("creator"), userElementType); Type mentionsElementType = new TypeToken<Collection<MentionDto>>() { }.getType(); List<MentionDto> mentions = gson.fromJson(obj.getAsJsonArray("mentions"), mentionsElementType); comment = new Comment(id, text, createdAt, user, mentions); } return comment; }