001: /**
002: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
003: * All Rights Reserved.
004: *
005: * This file is part of jWebTk.
006: *
007: * jWebTk is free software; you can redistribute it and/or modify it under
008: * the terms of the GNU General Public License (Version 2) as published by
009: * the Free Software Foundation.
010: *
011: * jWebTk is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with jWebTk; if not, write to the Free Software Foundation,
018: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
019: */package jwebtk.payment;
020:
021: import com.paypal.sdk.profiles.APIProfile;
022: import com.paypal.sdk.profiles.ProfileFactory;
023: import com.paypal.sdk.services.CallerServices;
024: import com.paypal.soap.api.AckCodeType;
025: import com.paypal.soap.api.AddressType;
026: import com.paypal.soap.api.BasicAmountType;
027: import com.paypal.soap.api.CountryCodeType;
028: import com.paypal.soap.api.CreditCardDetailsType;
029: import com.paypal.soap.api.CreditCardTypeType;
030: import com.paypal.soap.api.CurrencyCodeType;
031: import com.paypal.soap.api.DoDirectPaymentRequestDetailsType;
032: import com.paypal.soap.api.DoDirectPaymentRequestType;
033: import com.paypal.soap.api.DoDirectPaymentResponseType;
034: import com.paypal.soap.api.PayerInfoType;
035: import com.paypal.soap.api.PaymentActionCodeType;
036: import com.paypal.soap.api.PaymentDetailsType;
037: import com.paypal.soap.api.PersonNameType;
038: import java.util.Calendar;
039: import java.util.Map;
040: import java.util.TreeMap;
041:
042: /**
043: * This class sets up a PayPal backend payment interface that is unseen by the user. You'll need a PayPal account for direct payment processing.
044: */
045:
046: @SuppressWarnings("unchecked")
047: // working to complete a Java 1.5 version
048: public class DirectPayment {
049: static Map credit_card_types, states_provinces,
050: additional_states_provinces, countries;
051: CallerServices caller = new CallerServices();
052:
053: static {
054: credit_card_types = new TreeMap();
055:
056: credit_card_types.put("Amex", CreditCardTypeType.Amex);
057: credit_card_types.put("Discover", CreditCardTypeType.Discover);
058: credit_card_types.put("MasterCard",
059: CreditCardTypeType.MasterCard);
060: credit_card_types.put("Solo", CreditCardTypeType.Solo);
061: credit_card_types.put("Switch", CreditCardTypeType.Switch);
062: credit_card_types.put("Visa", CreditCardTypeType.Visa);
063:
064: states_provinces = new TreeMap();
065:
066: states_provinces.put("Alabama", "AL");
067: states_provinces.put("Alaska", "AK");
068: states_provinces.put("Arizona", "AZ");
069: states_provinces.put("Arkansas", "AR");
070: states_provinces.put("California", "CA");
071: states_provinces.put("Colorado", "CO");
072: states_provinces.put("Connecticut", "CT");
073: states_provinces.put("Delaware", "DE");
074: states_provinces.put("District of Columbia", "DC");
075: states_provinces.put("Florida", "FL");
076: states_provinces.put("Georgia", "GA");
077: states_provinces.put("Hawaii", "HI");
078: states_provinces.put("Idaho", "ID");
079: states_provinces.put("Illinois", "IL");
080: states_provinces.put("Indiana", "IN");
081: states_provinces.put("Iowa", "IA");
082: states_provinces.put("Kansas", "KS");
083: states_provinces.put("Kentucky", "KY");
084: states_provinces.put("Louisiana", "LA");
085: states_provinces.put("Maine", "ME");
086: states_provinces.put("Maryland", "MD");
087: states_provinces.put("Massachusetts", "MA");
088: states_provinces.put("Michigan", "MI");
089: states_provinces.put("Minnesota", "MN");
090: states_provinces.put("Mississippi", "MS");
091: states_provinces.put("Missouri", "MO");
092: states_provinces.put("Montana", "MT");
093: states_provinces.put("Nebraska", "NE");
094: states_provinces.put("Nevada", "NV");
095: states_provinces.put("New Hampshire", "NH");
096: states_provinces.put("New Jersey", "NJ");
097: states_provinces.put("New Mexico", "NM");
098: states_provinces.put("New York", "NY");
099: states_provinces.put("North Carolina", "NC");
100: states_provinces.put("North Dakota", "ND");
101: states_provinces.put("Ohio", "OH");
102: states_provinces.put("Oklahoma", "OK");
103: states_provinces.put("Oregon", "OR");
104: states_provinces.put("Pennsylvania", "PA");
105: states_provinces.put("Rhode Island", "RI");
106: states_provinces.put("South Carolina", "SC");
107: states_provinces.put("South Dakota", "SD");
108: states_provinces.put("Tennessee", "TN");
109: states_provinces.put("Texas", "TX");
110: states_provinces.put("Utah", "UT");
111: states_provinces.put("Vermont", "VT");
112: states_provinces.put("Virginia", "VA");
113: states_provinces.put("Washington", "WA");
114: states_provinces.put("West Virginia", "WV");
115: states_provinces.put("Wisconsin", "WI");
116: states_provinces.put("Wyoming", "WY");
117:
118: additional_states_provinces = new TreeMap();
119:
120: additional_states_provinces.put("American Samoa", "AS");
121: additional_states_provinces.put(
122: "Federated States of Micronesia", "FM");
123: additional_states_provinces.put("Guam", "GU");
124: additional_states_provinces.put("Marshall Islands", "MH");
125: additional_states_provinces.put("Northern Mariana Islands",
126: "MP");
127: additional_states_provinces.put("Palau", "PW");
128: additional_states_provinces.put("Puerto Rico", "PR");
129: additional_states_provinces.put("Virgin Islands", "VI");
130: additional_states_provinces.put("Armed Forces Americas", "AA");
131: additional_states_provinces.put("Armed Forces", "AE");
132: additional_states_provinces.put("Armed Forces Pacific", "AP");
133: additional_states_provinces.put("Alberta", "AB");
134: additional_states_provinces.put("British Columbia", "BC");
135: additional_states_provinces.put("Manitoba", "MB");
136: additional_states_provinces.put("New Brunswick", "NB");
137: additional_states_provinces.put("Newfoundland and Labrador",
138: "NF");
139: additional_states_provinces.put("Northwest Territories", "NT");
140: additional_states_provinces.put("Nova Scotia", "NS");
141: additional_states_provinces.put("Nunavut", "NU");
142: additional_states_provinces.put("Ontario", "ON");
143: additional_states_provinces.put("Prince Edward Island", "PE");
144: additional_states_provinces.put("Quebec", "QC");
145: additional_states_provinces.put("Saskatchewan", "SK");
146: additional_states_provinces.put("Yukon", "YK");
147:
148: countries = new TreeMap();
149:
150: countries.put("AFGHANISTAN", "AF");
151: countries.put("ÅLAND ISLANDS", "AX");
152: countries.put("ALBANIA", "AL");
153: countries.put("ALGERIA", "DZ");
154: countries.put("AMERICAN SAMOA", "AS");
155: countries.put("ANDORRA", "AD");
156: countries.put("ANGOLA", "AO");
157: countries.put("ANGUILLA", "AI");
158: countries.put("ANTARCTICA", "AQ");
159: countries.put("ANTIGUA AND BARBUDA", "AG");
160: countries.put("ARGENTINA", "AR");
161: countries.put("ARMENIA", "AM");
162: countries.put("ARUBA", "AW");
163: countries.put("AUSTRALIA", "AU");
164: countries.put("AUSTRIA", "AT");
165: countries.put("AZERBAIJAN", "AZ");
166: countries.put("BAHAMAS", "BS");
167: countries.put("BAHRAIN", "BH");
168: countries.put("BANGLADESH", "BD");
169: countries.put("BARBADOS", "BB");
170: countries.put("BELARUS", "BY");
171: countries.put("BELGIUM", "BE");
172: countries.put("BELIZE", "BZ");
173: countries.put("BENIN", "BJ");
174: countries.put("BERMUDA", "BM");
175: countries.put("BHUTAN", "BT");
176: countries.put("BOLIVIA", "BO");
177: countries.put("BOSNIA AND HERZEGOVINA", "BA");
178: countries.put("BOTSWANA", "BW");
179: countries.put("BOUVET ISLAND", "BV");
180: countries.put("BRAZIL", "BR");
181: countries.put("BRITISH INDIAN OCEAN TERRITORY", "IO");
182: countries.put("BRUNEI DARUSSALAM", "BN");
183: countries.put("BULGARIA", "BG");
184: countries.put("BURKINA FASO", "BF");
185: countries.put("BURUNDI", "BI");
186: countries.put("CAMBODIA", "KH");
187: countries.put("CAMEROON", "CM");
188: countries.put("CANADA", "CA");
189: countries.put("CAPE VERDE", "CV");
190: countries.put("CAYMAN ISLANDS", "KY");
191: countries.put("CENTRAL AFRICAN REPUBLIC", "CF");
192: countries.put("CHAD", "TD");
193: countries.put("CHILE", "CL");
194: countries.put("CHINA", "CN");
195: countries.put("CHRISTMAS ISLAND", "CX");
196: countries.put("COCOS (KEELING) ISLANDS", "CC");
197: countries.put("COLOMBIA", "CO");
198: countries.put("COMOROS", "KM");
199: countries.put("CONGO", "CG");
200: countries.put("CONGO, DEMOCRATIC REPUBLIC OF THE", "CD");
201: countries.put("COOK ISLANDS", "CK");
202: countries.put("COSTA RICA", "CR");
203: countries.put("COTE D'IVOIRE", "CI");
204: countries.put("CROATIA", "HR");
205: countries.put("CUBA", "CU");
206: countries.put("CYPRUS", "CY");
207: countries.put("CZECH REPUBLIC", "CZ");
208: countries.put("DENMARK", "DK");
209: countries.put("DJIBOUTI", "DJ");
210: countries.put("DOMINICA", "DM");
211: countries.put("DOMINICAN REPUBLIC", "DO");
212: countries.put("ECUADOR", "EC");
213: countries.put("EGYPT", "EG");
214: countries.put("EL SALVADOR", "SV");
215: countries.put("EQUATORIAL GUINEA", "GQ");
216: countries.put("ERITREA", "ER");
217: countries.put("ESTONIA", "EE");
218: countries.put("ETHIOPIA", "ET");
219: countries.put("FALKLAND ISLANDS (MALVINAS)", "FK");
220: countries.put("FAROE ISLANDS", "FO");
221: countries.put("FIJI", "FJ");
222: countries.put("FINLAND", "FI");
223: countries.put("FRANCE", "FR");
224: countries.put("FRENCH GUIANA", "GF");
225: countries.put("FRENCH POLYNESIA", "PF");
226: countries.put("FRENCH SOUTHERN TERRITORIES", "TF");
227: countries.put("GABON", "GA");
228: countries.put("GAMBIA", "GM");
229: countries.put("GEORGIA", "GE");
230: countries.put("GERMANY", "DE");
231: countries.put("GHANA", "GH");
232: countries.put("GIBRALTAR", "GI");
233: countries.put("GREECE", "GR");
234: countries.put("GREENLAND", "GL");
235: countries.put("GRENADA", "GD");
236: countries.put("GUADELOUPE", "GP");
237: countries.put("GUAM", "GU");
238: countries.put("GUATEMALA", "GT");
239: countries.put("GUERNSEY", "GG");
240: countries.put("GUINEA", "GN");
241: countries.put("GUINEA-BISSAU", "GW");
242: countries.put("GUYANA", "GY");
243: countries.put("HAITI", "HT");
244: countries.put("HEARD ISLAND AND MCDONALD ISLANDS", "HM");
245: countries.put("HOLY SEE (VATICAN CITY STATE)", "VA");
246: countries.put("HONDURAS", "HN");
247: countries.put("HONG KONG", "HK");
248: countries.put("HUNGARY", "HU");
249: countries.put("ICELAND", "IS");
250: countries.put("INDIA", "IN");
251: countries.put("INDONESIA", "ID");
252: countries.put("IRAN, ISLAMIC REPUBLIC OF", "IR");
253: countries.put("IRAQ", "IQ");
254: countries.put("IRELAND", "IE");
255: countries.put("ISLE OF MAN", "IM");
256: countries.put("ISRAEL", "IL");
257: countries.put("ITALY", "IT");
258: countries.put("JAMAICA", "JM");
259: countries.put("JAPAN", "JP");
260: countries.put("JERSEY", "JE");
261: countries.put("JORDAN", "JO");
262: countries.put("KAZAKHSTAN", "KZ");
263: countries.put("KENYA", "KE");
264: countries.put("KIRIBATI", "KI");
265: countries.put("KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF", "KP");
266: countries.put("KOREA, REPUBLIC OF", "KR");
267: countries.put("KUWAIT", "KW");
268: countries.put("KYRGYZSTAN", "KG");
269: countries.put("LAO PEOPLE'S DEMOCRATIC REPUBLIC", "LA");
270: countries.put("LATVIA", "LV");
271: countries.put("LEBANON", "LB");
272: countries.put("LESOTHO", "LS");
273: countries.put("LIBERIA", "LR");
274: countries.put("LIBYAN ARAB JAMAHIRIYA", "LY");
275: countries.put("LIECHTENSTEIN", "LI");
276: countries.put("LITHUANIA", "LT");
277: countries.put("LUXEMBOURG", "LU");
278: countries.put("MACAO", "MO");
279: countries.put("MACEDONIA, FORMER YUGOSLAV REPUBLIC OF", "MK");
280: countries.put("MADAGASCAR", "MG");
281: countries.put("MALAWI", "MW");
282: countries.put("MALAYSIA", "MY");
283: countries.put("MALDIVES", "MV");
284: countries.put("MALI", "ML");
285: countries.put("MALTA", "MT");
286: countries.put("MARSHALL ISLANDS", "MH");
287: countries.put("MARTINIQUE", "MQ");
288: countries.put("MAURITANIA", "MR");
289: countries.put("MAURITIUS", "MU");
290: countries.put("MAYOTTE", "YT");
291: countries.put("MEXICO", "MX");
292: countries.put("MICRONESIA, FEDERATED STATES OF", "FM");
293: countries.put("MOLDOVA, REPUBLIC OF", "MD");
294: countries.put("MONACO", "MC");
295: countries.put("MONGOLIA", "MN");
296: countries.put("MONTSERRAT", "MS");
297: countries.put("MOROCCO", "MA");
298: countries.put("MOZAMBIQUE", "MZ");
299: countries.put("MYANMAR", "MM");
300: countries.put("NAMIBIA", "NA");
301: countries.put("NAURU", "NR");
302: countries.put("NEPAL", "NP");
303: countries.put("NETHERLANDS", "NL");
304: countries.put("NETHERLANDS ANTILLES", "AN");
305: countries.put("NEW CALEDONIA", "NC");
306: countries.put("NEW ZEALAND", "NZ");
307: countries.put("NICARAGUA", "NI");
308: countries.put("NIGER", "NE");
309: countries.put("NIGERIA", "NG");
310: countries.put("NIUE", "NU");
311: countries.put("NORFOLK ISLAND", "NF");
312: countries.put("NORTHERN MARIANA ISLANDS", "MP");
313: countries.put("NORWAY", "NO");
314: countries.put("OMAN", "OM");
315: countries.put("PAKISTAN", "PK");
316: countries.put("PALAU", "PW");
317: countries.put("PALESTINIAN TERRITORY", "PS");
318: countries.put("PANAMA", "PA");
319: countries.put("PAPUA NEW GUINEA", "PG");
320: countries.put("PARAGUAY", "PY");
321: countries.put("PERU", "PE");
322: countries.put("PHILIPPINES", "PH");
323: countries.put("PITCAIRN", "PN");
324: countries.put("POLAND", "PL");
325: countries.put("PORTUGAL", "PT");
326: countries.put("PUERTO RICO", "PR");
327: countries.put("QATAR", "QA");
328: countries.put("REUNION", "RE");
329: countries.put("ROMANIA", "RO");
330: countries.put("RUSSIAN FEDERATION", "RU");
331: countries.put("RWANDA", "RW");
332: countries.put("SAINT HELENA", "SH");
333: countries.put("SAINT KITTS AND NEVIS", "KN");
334: countries.put("SAINT LUCIA", "LC");
335: countries.put("SAINT PIERRE AND MIQUELON", "PM");
336: countries.put("SAINT VINCENT AND THE GRENADINES", "VC");
337: countries.put("SAMOA", "WS");
338: countries.put("SAN MARINO", "SM");
339: countries.put("SAO TOME AND PRINCIPE", "ST");
340: countries.put("SAUDI ARABIA", "SA");
341: countries.put("SENEGAL", "SN");
342: countries.put("SERBIA AND MONTENEGRO", "CS");
343: countries.put("SEYCHELLES", "SC");
344: countries.put("SIERRA LEONE", "SL");
345: countries.put("SINGAPORE", "SG");
346: countries.put("SLOVAKIA", "SK");
347: countries.put("SLOVENIA", "SI");
348: countries.put("SOLOMON ISLANDS", "SB");
349: countries.put("SOMALIA", "SO");
350: countries.put("SOUTH AFRICA", "ZA");
351: countries.put("SOUTH GEORGIA AND SOUTH SANDWICH ISLANDS", "GS");
352: countries.put("SPAIN", "ES");
353: countries.put("SRI LANKA", "LK");
354: countries.put("SUDAN", "SD");
355: countries.put("SURINAME", "SR");
356: countries.put("SVALBARD AND JAN MAYEN", "SJ");
357: countries.put("SWAZILAND", "SZ");
358: countries.put("SWEDEN", "SE");
359: countries.put("SWITZERLAND", "CH");
360: countries.put("SYRIAN ARAB REPUBLIC", "SY");
361: countries.put("TAIWAN", "TW");
362: countries.put("TAJIKISTAN", "TJ");
363: countries.put("TANZANIA, UNITED REPUBLIC OF", "TZ");
364: countries.put("THAILAND", "TH");
365: countries.put("TIMOR-LESTE", "TL");
366: countries.put("TOGO", "TG");
367: countries.put("TOKELAU", "TK");
368: countries.put("TONGA", "TO");
369: countries.put("TRINIDAD AND TOBAGO", "TT");
370: countries.put("TUNISIA", "TN");
371: countries.put("TURKEY", "TR");
372: countries.put("TURKMENISTAN", "TM");
373: countries.put("TURKS AND CAICOS ISLANDS", "TC");
374: countries.put("TUVALU", "TV");
375: countries.put("UGANDA", "UG");
376: countries.put("UKRAINE", "UA");
377: countries.put("UNITED ARAB EMIRATES", "AE");
378: countries.put("UNITED KINGDOM", "GB");
379: countries.put("UNITED STATES", "US");
380: countries.put("UNITED STATES MINOR OUTLYING ISLANDS", "UM");
381: countries.put("URUGUAY", "UY");
382: countries.put("UZBEKISTAN", "UZ");
383: countries.put("VANUATU", "VU");
384: countries.put("VENEZUELA", "VE");
385: countries.put("VIET NAM", "VN");
386: countries.put("VIRGIN ISLANDS, BRITISH", "VG");
387: countries.put("VIRGIN ISLANDS, U.S.", "VI");
388: countries.put("WALLIS AND FUTUNA", "WF");
389: countries.put("WESTERN SAHARA", "EH");
390: countries.put("YEMEN", "YE");
391: countries.put("ZAMBIA", "ZM");
392: countries.put("ZIMBABWE", "ZW");
393:
394: }
395:
396: /**
397: * Sets up a DirectPayment backend payment interface.
398: *
399: *
400: * @param username the username expected
401: * @param password the password expected
402: * @param signature the signature expected
403: * @param environment the environment "sandbox" for testing or "live" for real
404: */
405:
406: public DirectPayment(String username, String password,
407: String signature, String environment)
408: throws PaymentException {
409: try {
410: APIProfile profile = ProfileFactory
411: .createSignatureAPIProfile();
412: profile.setAPIUsername(username);
413: profile.setAPIPassword(password);
414: profile.setSignature(signature);
415: profile.setEnvironment(environment);
416: caller.setAPIProfile(profile);
417: } catch (Exception e) {
418: throw new PaymentException(e);
419: }
420: }
421:
422: /**
423: * Sets up a DirectPayment backend payment interface.
424: *
425: *
426: * @param username the username expected by DirectPayment
427: * @param password the password expected by DirectPayment
428: * @param pkPassword the pkcs12 passphrase expected by DirectPayment
429: * @param certificateFile the path to the certificate file
430: * @param environment the environment "sandbox" for testing or "live" for real
431: */
432:
433: public DirectPayment(String username, String password,
434: String pkPassword, String certificateFile,
435: String environment) throws PaymentException {
436: try {
437: APIProfile profile = ProfileFactory
438: .createSignatureAPIProfile();
439: profile.setAPIUsername(username);
440: profile.setAPIPassword(password);
441: profile.setPrivateKeyPassword(pkPassword);
442: profile.setCertificateFile(certificateFile);
443: profile.setEnvironment(environment);
444: caller.setAPIProfile(profile);
445: } catch (Exception e) {
446: throw new PaymentException(e);
447: }
448: }
449:
450: /**
451: * Define credit card information
452: */
453:
454: public static class CreditCardInformation {
455: String credit_card, card_type, cvv, exp_month, exp_year;
456:
457: public CreditCardInformation(String creditCard,
458: String cardType, String expirationMonth,
459: String expirationYear) {
460: this (creditCard, cardType, null, expirationMonth,
461: expirationYear);
462: }
463:
464: public CreditCardInformation(String creditCard,
465: String cardType, String creditcardVerificationValue,
466: String expirationMonth, String expirationYear) {
467: this .credit_card = creditCard;
468: this .card_type = cardType;
469: this .cvv = creditcardVerificationValue;
470: this .exp_month = expirationMonth;
471: this .exp_year = expirationYear;
472: }
473: }
474:
475: /**
476: * Define credit card owner information
477: */
478:
479: public static class CardOwnerInformation {
480: String first_name, last_name, street1, street2, city, state,
481: postal_code, country;
482:
483: public CardOwnerInformation(String firstName, String lastName,
484: String street1, String street2, String city,
485: String state, String postalCode, String country) {
486: this .first_name = firstName;
487: this .last_name = lastName;
488: this .street1 = street1;
489: this .street2 = street2;
490: this .city = city;
491: this .state = state;
492: this .postal_code = postalCode;
493: this .country = country;
494: }
495: }
496:
497: /**
498: * The response information returned by DirectPayment
499: */
500:
501: public static class PaymentResponse {
502: DoDirectPaymentResponseType r;
503:
504: public PaymentResponse(DoDirectPaymentResponseType r) {
505: this .r = r;
506: }
507:
508: public String getCvv2Code() {
509: return r.getCVV2Code();
510: }
511:
512: public String getCorrelationId() {
513: return r.getCorrelationID();
514: }
515:
516: public String getAvsCode() {
517: return r.getAVSCode();
518: }
519:
520: public String getAcknowledgement() {
521: return r.getAck().toString();
522: }
523:
524: public String getAmount() {
525: return r.getAmount().toString();
526: }
527:
528: public String getTransactionId() {
529: return r.getTransactionID();
530: }
531:
532: public Calendar getTimestamp() {
533: return r.getTimestamp();
534: }
535:
536: public boolean getSuccess() {
537: return r.getAck().equals(AckCodeType.Success)
538: || r.getAck()
539: .equals(AckCodeType.SuccessWithWarning);
540: }
541:
542: public String getShortMessage() {
543: String message = null;
544:
545: if (r.getErrors() != null && r.getErrors().length > 0) {
546: message = "";
547:
548: for (int i = 0; i < r.getErrors().length; i++)
549: message += r.getErrors()[i].getShortMessage()
550: + "<br>";
551: }
552:
553: return message;
554: }
555:
556: public String getLongMessage() {
557: String message = null;
558:
559: if (r.getErrors() != null && r.getErrors().length > 0) {
560: message = "";
561:
562: for (int i = 0; i < r.getErrors().length; i++)
563: message += r.getErrors()[i].getLongMessage()
564: + "<br>";
565: }
566:
567: return message;
568: }
569: }
570:
571: /**
572: * Process a direct payment via DirectPayment.
573: *
574: *
575: * @param ip the IP address of the user (fraud prevention)
576: * @param amount total amount of the payment
577: * @param cci credit card information
578: * @param coi credit card owner information
579: * @return result of the transaction
580: */
581:
582: public PaymentResponse directPayment(String ip, double amount,
583: CreditCardInformation cci, CardOwnerInformation coi)
584: throws PaymentException {
585: DoDirectPaymentRequestType request = new DoDirectPaymentRequestType();
586: DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType();
587:
588: details.setIPAddress(ip);
589: details.setPaymentAction(PaymentActionCodeType.Sale);
590:
591: CreditCardDetailsType creditCard = new CreditCardDetailsType();
592: creditCard.setCreditCardNumber(cci.credit_card);
593: creditCard.setCreditCardType(CreditCardTypeType
594: .fromString(cci.card_type));
595: creditCard.setCVV2(cci.cvv);
596: creditCard.setExpMonth(new Integer(cci.exp_month).intValue());
597: creditCard.setExpYear(new Integer(cci.exp_year).intValue());
598:
599: PayerInfoType cardOwner = new PayerInfoType();
600:
601: PersonNameType payerName = new PersonNameType();
602: payerName.setFirstName(coi.first_name);
603: payerName.setLastName(coi.last_name);
604: cardOwner.setPayerName(payerName);
605:
606: AddressType address = new AddressType();
607: address.setStreet1(coi.street1);
608:
609: if (coi.street2 != null)
610: address.setStreet1(coi.street1);
611:
612: address.setCityName(coi.city);
613: address.setStateOrProvince(coi.state);
614: address.setPostalCode(coi.postal_code);
615: address.setCountry(CountryCodeType.fromString(coi.country));
616: cardOwner.setAddress(address);
617:
618: creditCard.setCardOwner(cardOwner);
619: details.setCreditCard(creditCard);
620:
621: PaymentDetailsType payment = new PaymentDetailsType();
622:
623: BasicAmountType orderTotal = new BasicAmountType();
624: orderTotal.setCurrencyID(CurrencyCodeType.USD);
625: orderTotal.set_value(new Double(amount).toString());
626: payment.setOrderTotal(orderTotal);
627:
628: details.setPaymentDetails(payment);
629: request.setDoDirectPaymentRequestDetails(details);
630:
631: try {
632: return new PaymentResponse(
633: (DoDirectPaymentResponseType) caller.call(
634: "DoDirectPayment", request));
635: } catch (Exception e) {
636: throw new PaymentException(e);
637: }
638: }
639:
640: /**
641: * States, Provinces and their codes that DirectPayment supports
642: */
643:
644: public static Map getStatesProvinces() {
645: return states_provinces;
646: }
647:
648: /**
649: * Additional states, provinces and their codes that DirectPayment supports
650: */
651:
652: public static Map getAdditionalStatesProvinces() {
653: return additional_states_provinces;
654: }
655:
656: /**
657: * Countries and their codes that DirectPayment supports
658: */
659:
660: public static Map getCountries() {
661: return countries;
662: }
663:
664: /**
665: * Credit card types supported by DirectPayment
666: */
667:
668: public static Map getCreditCardTypes() {
669: return credit_card_types;
670: }
671: /*
672: public static void main(String[] args)
673: {
674: try
675: {
676: DirectPayment pp = new DirectPayment("test_api1.softwaresensation.com","VBAACCMQ5CN3V96D","AXuvVdpyAeZUtSJ1yWJuCV6a8i33AdI-s9Lloti4HOkrytGZR7PeCH1q","sandbox");
677:
678: CreditCardInformation cci = new CreditCardInformation("4721930402892796", "Visa", "000", "11", "2007");
679: CardOwnerInformation coi = new CardOwnerInformation("David", "Bulmore", "123 dfhufidh", null, "Glendale", "AZ", "43844", "US");
680:
681: pp.directPayment("12.36.5.78",123.99,cci,coi);
682: }
683: catch (Exception e)
684: {
685: e.printStackTrace();
686: }
687: }
688: */
689: }
|