Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Case Study: Automating Payment  (Read 3491 times)
0 Members and 1 Guest are viewing this topic.
Morten
Guest
« Posted 2006-05-15 21:51:36 »

I would like to share with the java gaming community my experiences with online payments. Because we're entering the participation age, it's important for me to focus on the advantages of sharing the revenues of our company with the customers. Customers in the participation age is more than consumers, they're active participants who add value to the site. This added value attracts more buyers. I expect that it will soon - sometimes - be a sound buisiness decision to pay, yes, to pay your customers.

Automating the payment process with Java is much simpler than one would expect. I'd like to give an example of how this can be done.

Last year I experimented with some code that makes a lookup in a database and logs into my companys PayPal account and transfers money to other accounts, based on the information in this database. PayPal is a HTTPS site. The code underneeth has no database logic but simply logs into PayPal and transfers money to another account.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
package indie.postmoderngames.paypal;

import com.meterware.httpunit.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * <p>Copyleft (L) 2002-2006. All rights reserved.</p>
 * <p>Donated by Post Modern Games</p>
 *
 * @author Morten
 * @version 1.01 03-02-2005
 */

public class PaypalProxy
{
    public PaypalProxy()
    {
        try {
            // create the conversation object which will maintain state for us
           WebConversation wc = new WebConversation();

            // Obtain the main page on the meterware web site
           WebRequest request = new GetMethodWebRequest( "https://www.paypal.com" );
            WebResponse response = wc.getResponse( request );

            WebForm webForm = response.getFormWithName("login_form");
            webForm.setParameter("login_email", "<your email here>");
            webForm.setParameter("login_password","<your password here>");

            WebResponse r2 = webForm.submit();

            WebLink link = r2.getFirstMatchingLink(WebLink.MATCH_CONTAINED_TEXT, "click here");
            WebResponse r3 = link.click();

            WebLink link2 = r3.getFirstMatchingLink(WebLink.MATCH_URL_STRING, "_transaction-run");
            WebResponse r4 = link2.click();
            WebForm form2 = r4.getFormWithName("focusform");
            form2.setParameter("email","<receiver email here>");
            form2.setParameter("amount","0.01");
            form2.setParameter("amount_ccode","AUD");
            form2.setParameter("payment_type","S");
            form2.setParameter("subject", "Coin1 has sent you money");
            form2.setParameter("note", "You have received money.");
            WebResponse r5 = form2.submit();

            WebForm[] forms = r5.getForms();
            System.out.println("number of forms: " + forms.length);

            WebForm form3 = forms[0];
            SubmitButton submit = form3.getSubmitButton("submit.x");

            WebResponse r6 = form3.submit(submit);

            BufferedReader input = new BufferedReader(new InputStreamReader(r6.getInputStream(), "UTF8"));
            String str;
            while (null != ((str = input.readLine()))) {
                System.out.println(str);
            }
        } catch (Exception e) {
            System.err.println( "Exception: " + e );
            e.printStackTrace();
        }
    }

    public static void main(String[] args)
    {
        new PaypalProxy();
    }
}



The code is for you to take.

Best regards Morten
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #1 - Posted 2006-05-15 23:04:08 »

That's pretty easy to understand! Thanks for sharing.  Smiley

I have two questions:
1. It does not seem you are using the PayPal API, but rather access the web site: "r4.getFormWithName("focusform");". What happens if PayPal decides to change from let's say "focusform" -> "F_FORM"? Does your program still work? Or how do you cope with that?

2. Did you try the PayPal API? I saw some Java SDK to access PayPal before. This might be more reliable?

Morten
Guest
« Reply #2 - Posted 2006-05-15 23:46:20 »

Hi again Kingaschi - our first user  Grin

1. On that occasion it doesn't work. You're right.

2. Thanks for the suggestion. I wasn't aware of this API.

br Morten
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #3 - Posted 2006-05-15 23:49:29 »

I never tried it, but you can get the Java SDK for PayPal from: https://www.paypal.com/IntegrationCenter/ic_sdk-resource.html.

Morten
Guest
« Reply #4 - Posted 2006-05-16 21:05:09 »

Thanks. Best of luck Kingaschi!

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (34 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!