public String build()
    {
        this.message_string  = "{";

            if( this.recipient_id != null ){
                this.message_string += "\"recipient\": {\"id\": \"" + this.recipient_id + "\"},";
            }

            this.message_string += "\"message\": {";

                this.message_string += "\"attachment\":{";

                    this.message_string += "\"type\":\"template\",";
                    this.message_string += "\"payload\":{";

                        this.message_string += "\"template_type\":\"receipt\",";

                        if( this.recipient_name != null ){
                            this.message_string += "\"recipient_name\":\"" + this.recipient_name + "\",";
                        }
                        if( this.order_number != null ){
                            this.message_string += "\"order_number\":\"" + this.order_number + "\",";
                        }
                        if( this.currency != null ){
                            this.message_string += "\"currency\":\"" + this.currency + "\",";
                        }
                        if( this.payment_method != null ){
                            this.message_string += "\"payment_method\":\"" + this.payment_method + "\",";
                        }
                        if( this.order_url != null ){
                            this.message_string += "\"order_url\":\"" + this.order_url + "\",";
                        }
                        if( this.timestamp != null ){
                            this.message_string += "\"timestamp\":\"" + this.timestamp + "\",";
                        }

                        if( !this.elements.isEmpty() ){
                            this.message_string += "\"elements\":[";
                            for ( int j = 0 ; j < this.elements.size(); j++ ) {
                                HashMap<String, String> element = this.elements.get(j);

                                this.message_string += "{";
                                    if( !element.get("title").equals("") ){
                                        this.message_string += "\"title\":\"" + element.get("title") + "\",";
                                    }
                                    if( !element.get("subtitle").equals("") ){
                                        this.message_string += "\"subtitle\":\"" + element.get("subtitle") + "\",";
                                    }
                                    if( !element.get("quantity").equals("") ){
                                        this.message_string += "\"quantity\":" + element.get("quantity") + ",";
                                    }
                                    if( !element.get("price").equals("") ){
                                        this.message_string += "\"price\":" + element.get("price") + ",";
                                    }
                                    if( !element.get("currency").equals("") ){
                                        this.message_string += "\"currency\":\"" + element.get("currency") + "\",";
                                    }
                                    if( !element.get("image_url").equals("") ){
                                        this.message_string += "\"image_url\":\"" + element.get("image_url") + "\",";
                                    }

                                    this.message_string = this.message_string.replaceAll(",$", "");
                                this.message_string += "},";

                            }
                            this.message_string = this.message_string.replaceAll(",$", "");
                            this.message_string += "],";
                        }

                        if( !this.address.isEmpty() ){
                            this.message_string += "\"address\":{";

                                if( !this.address.get("street_1").equals("") ){
                                    this.message_string += "\"street_1\":\"" + this.address.get("street_1") + "\",";
                                }
                                if( !this.address.get("street_2").equals("") ){
                                    this.message_string += "\"street_2\":\"" + this.address.get("street_2") + "\",";
                                }
                                if( !this.address.get("city").equals("") ){
                                    this.message_string += "\"city\":\"" + this.address.get("city") + "\",";
                                }
                                if( !this.address.get("postal_code").equals("") ){
                                    this.message_string += "\"postal_code\":\"" + this.address.get("postal_code") + "\",";
                                }
                                if( !this.address.get("state").equals("") ){
                                    this.message_string += "\"state\":\"" + this.address.get("state") + "\",";
                                }
                                if( !this.address.get("country").equals("") ){
                                    this.message_string += "\"country\":\"" + this.address.get("country") + "\",";
                                }

                                this.message_string = this.message_string.replaceAll(",$", "");

                            this.message_string += "},";
                        }

                        if( !this.summary.isEmpty() ){
                            this.message_string += "\"summary\":{";

                                if( !this.summary.get("subtotal").equals("") ){
                                    this.message_string += "\"subtotal\":" + this.summary.get("subtotal") + ",";
                                }
                                if( !this.summary.get("shipping_cost").equals("") ){
                                    this.message_string += "\"shipping_cost\":" + this.summary.get("shipping_cost") + ",";
                                }
                                if( !this.summary.get("total_tax").equals("") ){
                                    this.message_string += "\"total_tax\":" + this.summary.get("total_tax") + ",";
                                }
                                if( !this.summary.get("total_cost").equals("") ){
                                    this.message_string += "\"total_cost\":" + this.summary.get("total_cost") + ",";
                                }

                                this.message_string = this.message_string.replaceAll(",$", "");

                            this.message_string += "},";
                        }
                        if( !this.adjustments.isEmpty() ){
                            this.message_string += "\"adjustments\":[";
                            for ( int j = 0 ; j < this.adjustments.size(); j++ ) {
                                HashMap<String, String> adjustment = this.adjustments.get(j);

                                this.message_string += "{";
                                    if( !adjustment.get("name").equals("") ){
                                        this.message_string += "\"name\":\"" + adjustment.get("name") + "\",";
                                    }
                                    if( !adjustment.get("amount").equals("") ){
                                        this.message_string += "\"amount\":" + adjustment.get("amount") + ",";
                                    }
                                    this.message_string = this.message_string.replaceAll(",$", "");
                                this.message_string += "},";

                            }
                            this.message_string = this.message_string.replaceAll(",$", "");
                            this.message_string += "],";
                        }

                        this.message_string = this.message_string.replaceAll(",$", "");

                    this.message_string += "}";

                this.message_string += "}";

            this.message_string += "}";

        this.message_string += "}";

        return this.message_string;
    }
public String build ( ) { this . message_string = "{" ; if ( this . recipient_id != null ) { this . message_string += "\"recipient\": {\"id\": \"" + this . recipient_id + "\"}," ; } this . message_string += "\"message\": {" ; this . message_string += "\"attachment\":{" ; this . message_string += "\"type\":\"template\"," ; this . message_string += "\"payload\":{" ; this . message_string += "\"template_type\":\"receipt\"," ; if ( this . recipient_name != null ) { this . message_string += "\"recipient_name\":\"" + this . recipient_name + "\"," ; } if ( this . order_number != null ) { this . message_string += "\"order_number\":\"" + this . order_number + "\"," ; } if ( this . currency != null ) { this . message_string += "\"currency\":\"" + this . currency + "\"," ; } if ( this . payment_method != null ) { this . message_string += "\"payment_method\":\"" + this . payment_method + "\"," ; } if ( this . order_url != null ) { this . message_string += "\"order_url\":\"" + this . order_url + "\"," ; } if ( this . timestamp != null ) { this . message_string += "\"timestamp\":\"" + this . timestamp + "\"," ; } if ( ! this . elements . isEmpty ( ) ) { this . message_string += "\"elements\":[" ; for ( int j = 0 ; j < this . elements . size ( ) ; j ++ ) { HashMap < String , String > element = this . elements . get ( j ) ; this . message_string += "{" ; if ( ! element . get ( "title" ) . equals ( "" ) ) { this . message_string += "\"title\":\"" + element . get ( "title" ) + "\"," ; } if ( ! element . get ( "subtitle" ) . equals ( "" ) ) { this . message_string += "\"subtitle\":\"" + element . get ( "subtitle" ) + "\"," ; } if ( ! element . get ( "quantity" ) . equals ( "" ) ) { this . message_string += "\"quantity\":" + element . get ( "quantity" ) + "," ; } if ( ! element . get ( "price" ) . equals ( "" ) ) { this . message_string += "\"price\":" + element . get ( "price" ) + "," ; } if ( ! element . get ( "currency" ) . equals ( "" ) ) { this . message_string += "\"currency\":\"" + element . get ( "currency" ) + "\"," ; } if ( ! element . get ( "image_url" ) . equals ( "" ) ) { this . message_string += "\"image_url\":\"" + element . get ( "image_url" ) + "\"," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "}," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "]," ; } if ( ! this . address . isEmpty ( ) ) { this . message_string += "\"address\":{" ; if ( ! this . address . get ( "street_1" ) . equals ( "" ) ) { this . message_string += "\"street_1\":\"" + this . address . get ( "street_1" ) + "\"," ; } if ( ! this . address . get ( "street_2" ) . equals ( "" ) ) { this . message_string += "\"street_2\":\"" + this . address . get ( "street_2" ) + "\"," ; } if ( ! this . address . get ( "city" ) . equals ( "" ) ) { this . message_string += "\"city\":\"" + this . address . get ( "city" ) + "\"," ; } if ( ! this . address . get ( "postal_code" ) . equals ( "" ) ) { this . message_string += "\"postal_code\":\"" + this . address . get ( "postal_code" ) + "\"," ; } if ( ! this . address . get ( "state" ) . equals ( "" ) ) { this . message_string += "\"state\":\"" + this . address . get ( "state" ) + "\"," ; } if ( ! this . address . get ( "country" ) . equals ( "" ) ) { this . message_string += "\"country\":\"" + this . address . get ( "country" ) + "\"," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "}," ; } if ( ! this . summary . isEmpty ( ) ) { this . message_string += "\"summary\":{" ; if ( ! this . summary . get ( "subtotal" ) . equals ( "" ) ) { this . message_string += "\"subtotal\":" + this . summary . get ( "subtotal" ) + "," ; } if ( ! this . summary . get ( "shipping_cost" ) . equals ( "" ) ) { this . message_string += "\"shipping_cost\":" + this . summary . get ( "shipping_cost" ) + "," ; } if ( ! this . summary . get ( "total_tax" ) . equals ( "" ) ) { this . message_string += "\"total_tax\":" + this . summary . get ( "total_tax" ) + "," ; } if ( ! this . summary . get ( "total_cost" ) . equals ( "" ) ) { this . message_string += "\"total_cost\":" + this . summary . get ( "total_cost" ) + "," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "}," ; } if ( ! this . adjustments . isEmpty ( ) ) { this . message_string += "\"adjustments\":[" ; for ( int j = 0 ; j < this . adjustments . size ( ) ; j ++ ) { HashMap < String , String > adjustment = this . adjustments . get ( j ) ; this . message_string += "{" ; if ( ! adjustment . get ( "name" ) . equals ( "" ) ) { this . message_string += "\"name\":\"" + adjustment . get ( "name" ) + "\"," ; } if ( ! adjustment . get ( "amount" ) . equals ( "" ) ) { this . message_string += "\"amount\":" + adjustment . get ( "amount" ) + "," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "}," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "]," ; } this . message_string = this . message_string . replaceAll ( ",$" , "" ) ; this . message_string += "}" ; this . message_string += "}" ; this . message_string += "}" ; this . message_string += "}" ; return this . message_string ; }
Build and get message as a string

@return String the final message body