Skip to content

Instantly share code, notes, and snippets.

@appikonda
Created August 12, 2015 20:24
Show Gist options
  • Save appikonda/8137bceb90d7354274e5 to your computer and use it in GitHub Desktop.
Save appikonda/8137bceb90d7354274e5 to your computer and use it in GitHub Desktop.
Convert IPN Response to JSON
mc_gross=19.95
protection_eligibility=Eligible
address_status=confirmed
payer_id=LPLWNMTBWMFAY
tax=0.00
address_street=1+Main+St
payment_date=20%3A12%3A59+Jan+13%2C+2009+PST
payment_status=Completed
charset=windows-1252
address_zip=95131
first_name=Test
mc_fee=0.88
address_country_code=US
address_name=Test+User
notify_version=2.6
custom=
payer_status=verified
address_country=United+States
address_city=San+Jose
quantity=1
verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf
payer_email=gpmac_1231902590_per%40paypal.com
txn_id=61E67681CH3238416
payment_type=instant
last_name=User
address_state=CA
receiver_email=gpmac_1231902686_biz%40paypal.com
payment_fee=0.88
receiver_id=S8XGHLYDW9T3S
txn_type=express_checkout
item_name=
mc_currency=USD
item_number=
residence_country=US
test_ipn=1
handling_amount=0.00
transaction_subject=
payment_gross=19.95
shipping=0.00
@appikonda
Copy link
Author

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

public class Reader {

private static HashMap<String, String> map = new HashMap<String, String>();

public static void main(String[] args) {



    String target = "mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&address_name=Test+User&notify_version=2.6&custom=&payer_status=verified&address_country=United+States&address_city=San+Jose&quantity=1&verify_sign=AtkOfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH3238416&payment_type=instant&last_name=User&address_state=CA&receiver_email=gpmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=19.95&shipping=0.00";
    String[] tokens = target.split("&");            
    for (int i = 0; i < tokens.length; i++) {
          addToMap(tokens[i]);
    }

    System.out.println(map);

}

public static void addToMap(String token) {
String[] tokens = token.split("=");
if(tokens.length == 2)
{
if(!map.containsKey(tokens[0]))
{
map.put(tokens[0], tokens[1]);
}
}

}

/*
BufferedReader br = null;

try {

    String sCurrentLine;

    br = new BufferedReader(new FileReader("C:\\Users\\sappikonda\\Desktop\\response.txt"));

   Scanner sc = new Scanner();
    while ((sCurrentLine = br.readLine()) != null) {
        System.out.println(sCurrentLine);
    }

} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (br != null)br.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}*/

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment