Created
December 17, 2016 13:55
-
-
Save MrPowerGamerBR/85ffcf8b942af5f17e0283fa14bfe7e3 to your computer and use it in GitHub Desktop.
Small Gson wrapper (?) for MercadoPago's Java SDK. Only with payment wrapper atm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.mrpowergamerbr.sparklysunnyfunny.utils; | |
| import java.util.ArrayList; | |
| import org.codehaus.jettison.json.JSONObject; | |
| import com.google.gson.Gson; | |
| import com.mercadopago.MP; | |
| public class MercadoUtils { | |
| public static final Gson gson = new Gson(); | |
| public static final MP mp = new MP(MercadoTokens.client_id, MercadoTokens.client_token); | |
| public static void main(String[] args) { | |
| System.out.println("Debugging..."); | |
| //getAccessToken(); | |
| PaymentResponseRoot prr = createPayment("Teste", 1, "BR", 10); | |
| System.out.println(prr.response.init_point); | |
| } | |
| public static PaymentResponseRoot createPayment(String title, int qty, String currencyId, double price) { | |
| JSONObject createPreferenceResult; | |
| PaymentRequest paymentRequest = new PaymentRequest(); | |
| PaymentItem payment = new PaymentItem(title, qty, currencyId, price); | |
| paymentRequest.items.add(payment); | |
| try { | |
| createPreferenceResult = mp.createPreference(gson.toJson(paymentRequest)); | |
| return gson.fromJson(createPreferenceResult.toString(), PaymentResponseRoot.class); | |
| } catch (Exception e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| return null; | |
| } | |
| } | |
| class PaymentRequest { | |
| ArrayList<PaymentItem> items = new ArrayList<PaymentItem>(); | |
| } | |
| class PaymentItem { | |
| public String id; | |
| public String title; | |
| public String description; | |
| public String category_id; | |
| public String picture_url; | |
| public String currency_id; | |
| public int quantity; | |
| public double unit_price; | |
| public PaymentItem(String title, int quantity, String currency_id, double unit_price) { | |
| this.title = title; | |
| this.quantity = quantity; | |
| this.currency_id = currency_id; | |
| this.unit_price = unit_price; | |
| } | |
| } | |
| class PaymentResponseRoot { | |
| public int status; | |
| public PaymentResponse response; | |
| } | |
| class PaymentResponse { | |
| public int collector_id; | |
| public String operation_type; | |
| ArrayList<PaymentItem> paymentItems; | |
| BackUrls back_urls; | |
| String auto_return; | |
| PaymentMethods payment_methods; | |
| int client_id; | |
| String marketplace; | |
| String marketplace_fee; | |
| Shipments shipments; | |
| String notification_url; | |
| String external_reference; | |
| String additional_info; | |
| boolean expires; | |
| String expiration_date_from; | |
| String expiration_date_to; | |
| String date_created; | |
| String id; | |
| String init_point; | |
| String sandbox_init_point; | |
| } | |
| class Payer { | |
| String name; | |
| String surname; | |
| String email; | |
| String date_created; | |
| Phone phone; | |
| Identification identification; | |
| Address address; | |
| } | |
| class Phone { | |
| String area_code; | |
| String number; | |
| } | |
| class Identification { | |
| String type; | |
| String number; | |
| } | |
| class Address { | |
| String street_name; | |
| String street_number; | |
| String zip_code; | |
| } | |
| class BackUrls { | |
| String success; | |
| String pending; | |
| String failure; | |
| } | |
| class PaymentMethods { | |
| ArrayList<PaymentMethod> excluded_payment_methods; | |
| ArrayList<PaymentType> excluded_payment_types; | |
| String installments; | |
| String default_payment_method_id; | |
| String default_installments; | |
| } | |
| class Shipments { | |
| ShipmentAddress receiver_address; | |
| } | |
| class ShipmentAddress { | |
| String zip_code; | |
| String street_number; | |
| String street_name; | |
| String floor; | |
| String apartment; | |
| } | |
| class PaymentMethod { | |
| String id; | |
| } | |
| class PaymentType { | |
| String id; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment