示例#1
0
 public static Checkout fetch(Long checkoutId, String accessToken)
     throws JSONException, IOException, WePayException {
   JSONObject params = new JSONObject();
   params.put("checkout_id", checkoutId);
   String response = request("/checkout", params, accessToken);
   Checkout c = gson.fromJson(response, Checkout.class);
   CheckoutData cd = gson.fromJson(response, CheckoutData.class);
   c.checkoutData = cd;
   return c;
 }
示例#2
0
  public static Checkout create(CheckoutData data, String accessToken)
      throws JSONException, IOException, WePayException {
    JSONObject params = new JSONObject();
    params.put("account_id", data.accountId);
    params.put("short_description", data.shortDescription);
    params.put("type", data.type);
    params.put("amount", data.amount);
    params.put("currency", data.currency);

    if (data.longDescription != null) params.put("long_description", data.longDescription);

    if (data.emailMessage != null)
      params.put("email_message", EmailMessageData.build_email_message(data.emailMessage));
    if (data.fee != null) params.put("fee", FeeData.build_fee(data.fee));

    if (data.callbackUri != null) params.put("callback_uri", data.callbackUri);
    if (data.autoCapture != null) params.put("auto_capture", data.autoCapture);
    if (data.referenceId != null) params.put("reference_id", data.referenceId);
    if (data.uniqueId != null) params.put("unique_id", data.uniqueId);

    if (data.hostedCheckout != null)
      params.put("hosted_checkout", HostedCheckoutData.build_hosted_checkout(data.hostedCheckout));

    if (data.paymentMethod != null)
      params.put("payment_method", PaymentMethodData.build_payment_method(data.paymentMethod));

    if (data.deliveryType != null) params.put("delivery_type", data.deliveryType);

    if (data.payerRbits != null) {
      String payerRbitsJson = gson.toJson(data.payerRbits);
      params.put("payer_rbits", new JSONArray(payerRbitsJson));
    }

    if (data.transactionRbits != null) {
      String transactionRbitsJson = gson.toJson(data.transactionRbits);
      params.put("transaction_rbits", new JSONArray(transactionRbitsJson));
    }

    String response = request("/checkout/create", params, accessToken);
    Checkout c = gson.fromJson(response, Checkout.class);
    CheckoutData cd = gson.fromJson(response, CheckoutData.class);

    if (data.emailMessage != null) {
      cd.emailMessage = data.emailMessage;
    }
    if (data.uniqueId != null) {
      cd.uniqueId = data.uniqueId;
    }
    if (data.hostedCheckout != null && data.hostedCheckout.fundingSources != null) {
      cd.hostedCheckout.fundingSources = data.hostedCheckout.fundingSources;
    }
    c.checkoutData = cd;

    return c;
  }
示例#3
0
 public static Checkout[] find(CheckoutFindData findData, String accessToken)
     throws JSONException, IOException, WePayException {
   JSONObject params = new JSONObject();
   if (findData.accountId != null) params.put("account_id", findData.accountId);
   if (findData.start != null) params.put("start", findData.start);
   if (findData.limit != null) params.put("limit", findData.limit);
   if (findData.referenceId != null) params.put("reference_id", findData.referenceId);
   if (findData.state != null) params.put("state", findData.state);
   if (findData.preapprovalId != null) params.put("preapproval_id", findData.preapprovalId);
   if (findData.startTime != null) params.put("start_time", findData.startTime);
   if (findData.endTime != null) params.put("end_time", findData.endTime);
   if (findData.sortOrder != null) params.put("sort_order", findData.sortOrder);
   if (findData.shippingFee != null) params.put("shipping_fee", findData.shippingFee);
   JSONArray results = new JSONArray(request("/checkout/find", params, accessToken));
   Checkout[] found = new Checkout[results.length()];
   for (int i = 0; i < found.length; i++) {
     Checkout c = gson.fromJson(results.get(i).toString(), Checkout.class);
     CheckoutData cd = gson.fromJson(results.get(i).toString(), CheckoutData.class);
     c.checkoutData = cd;
     found[i] = c;
   }
   return found;
 }