@Test public void testUpdatePreference() throws JSONException { JSONObject createPreferenceResult = mp.createPreference( "{'items':[{'title':'Prueba','quantity':1,'currency_id':'ARS','unit_price':10.5}]}"); String createdPreferenceId = createPreferenceResult.getJSONObject("response").getString("id"); JSONObject updatePreferenceResult = mp.updatePreference( createdPreferenceId, "{'items':[{'title':'Modified','quantity':2,'unit_price':2.2}]}"); assertEquals(updatePreferenceResult.getInt("status"), 200); JSONObject getPreferenceResult = mp.getPreference(createdPreferenceId); assertEquals(getPreferenceResult.getInt("status"), 200); JSONObject obtainedPreference = (JSONObject) getPreferenceResult.getJSONObject("response").getJSONArray("items").get(0); assertEquals(obtainedPreference.getString("title"), "Modified"); assertEquals(obtainedPreference.getInt("quantity"), 2); assertEquals(obtainedPreference.getDouble("unit_price"), 2, 2d); }
public static void main(String args[]) { MP mp = new MP("ACCESS_TOKEN"); JSONObject payment = mp.post( "/v1/payments", "{" + "'transaction_amount': 100," + "'description': 'Title of what you are paying for'," + "'payment_method_id': 'ATM_PAYMENT_METHOD_ID'," + "'payer': {" + "'email': '*****@*****.**'" + "}" + "}"); }
@Test public void testCreatePreference() throws JSONException { JSONObject createPreferenceResult = mp.createPreference( "{'items':[{'title':'Prueba','quantity':1,'currency_id':'ARS','unit_price':10.5}]}"); assertEquals(createPreferenceResult.getInt("status"), 201); JSONObject createdPreference = (JSONObject) createPreferenceResult.getJSONObject("response").getJSONArray("items").get(0); assertEquals(createdPreference.getString("title"), "Prueba"); assertEquals(createdPreference.getInt("quantity"), 1); assertEquals(createdPreference.getString("currency_id"), "ARS"); assertEquals(createdPreference.getDouble("unit_price"), 10, 5d); }