Android Open Source - Android-Print-SDK Check Promo Request






From Project

Back to project page Android-Print-SDK.

License

The source code is released under:

MIT License

If you think the Android project Android-Print-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ly.kite.payment;
//from w w w.j a  v a 2  s.co  m
import org.json.JSONObject;

import java.math.BigDecimal;

import ly.kite.print.BaseRequest;
import ly.kite.print.KitePrintSDK;
import ly.kite.print.KitePrintSDKException;
import ly.kite.print.PrintJob;
import ly.kite.print.PrintOrder;

/**
 * Created by deonbotha on 17/02/2014.
 */
public class CheckPromoRequest {

    private BaseRequest req;

    public void checkPromoCode(String promoCode, PrintOrder order, final CheckPromoCodeRequestListener listener) {
        if (req != null) throw new AssertionError("only one check promo code request can be in progress at a time");

        StringBuilder templateCostBreakdown = new StringBuilder();
        for (PrintJob j : order.getJobs()) {
            if (templateCostBreakdown.length() > 0) templateCostBreakdown.append(",");
            templateCostBreakdown.append(String.format("%s:%s", j.getTemplateName(), j.getCost().toString()));
        }

        String url = String.format("%s/v1/promo_code/check?code=%s&templates=%s&currency=GBP", KitePrintSDK.getEnvironment().getPrintAPIEndpoint(), promoCode, templateCostBreakdown.toString());
        req = new BaseRequest(BaseRequest.HttpMethod.GET, url, null, null);
        req.start(new BaseRequest.BaseRequestListener() {
            @Override
            public void onSuccess(int httpStatusCode, JSONObject json) {
                try {
                    if (httpStatusCode >= 200 && httpStatusCode <= 299) {
                        BigDecimal discount = new BigDecimal(json.getDouble("discount"));
                        listener.onDiscount(discount);
                    } else {
                        JSONObject error = json.getJSONObject("error");
                        String message = error.getString("message");
                        listener.onError(new KitePrintSDKException(message));
                    }
                } catch (Exception ex) {
                    listener.onError(ex);
                }
            }

            @Override
            public void onError(Exception ex) {
                listener.onError(ex);
            }
        });
    }

    public void cancel() {
        if (req != null) {
            req.cancel();
            req = null;
        }
    }

}




Java Source Code List

co.oceanlabs.sample.MainActivity.java
ly.kite.address.AddressBookActivity.java
ly.kite.address.AddressEditActivity.java
ly.kite.address.AddressSearchActivity.java
ly.kite.address.AddressSearchRequestListener.java
ly.kite.address.AddressSearchRequest.java
ly.kite.address.Address.java
ly.kite.address.Country.java
ly.kite.checkout.CheckoutActivity.java
ly.kite.checkout.OrderReceiptActivity.java
ly.kite.checkout.PaymentActivity.java
ly.kite.checkout.PrintOrderSummaryListAdapter.java
ly.kite.payment.CheckPromoCodeRequestListener.java
ly.kite.payment.CheckPromoRequest.java
ly.kite.payment.PayPalCardChargeListener.java
ly.kite.payment.PayPalCardVaultStorageListener.java
ly.kite.payment.PayPalCard.java
ly.kite.print.ApplyPromoCodeListener.java
ly.kite.print.AssetGetBytesLengthListener.java
ly.kite.print.AssetGetBytesListener.java
ly.kite.print.AssetUploadRequestListener.java
ly.kite.print.AssetUploadRequest.java
ly.kite.print.Asset.java
ly.kite.print.BaseRequest.java
ly.kite.print.KitePrintSDKException.java
ly.kite.print.KitePrintSDK.java
ly.kite.print.PrintJob.java
ly.kite.print.PrintOrderSubmissionListener.java
ly.kite.print.PrintOrder.java
ly.kite.print.PrintsPrintJob.java
ly.kite.print.ProductType.java
ly.kite.print.SubmitPrintOrderRequestListener.java
ly.kite.print.SubmitPrintOrderRequest.java