Posts Tagged ‘Arts’

Image representing PayPal as depicted in Crunc...

Basic Steps:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview#id09C2EN00EHT
NVP API Method and Field Reference: http://www.paypalobjects.com/en_US/ebook/PP_NVPAPI_DeveloperGuide/Appx_fieldreference.html#2830894

Here you can generate your desire paypal source code:
https://www.paypal-labs.com/integrationwizard/ecpaypal/code.php

Process of payment using PayPal checkout :
1. First, we generate a unique token id from paypal for each transaction , then start the
payment by passing the token to the paypal site:
2. Next, Send the merchant or seller account details with API signature to the paypal site.
So buyer can transfer money to seller account.

PaymentAction.java

public String expressCheckout(){
HttpSession session=request.getSession();
System.out.println(“return url: “+PaymentConstants.returnURL);
CallShortcutExpressCheckout(PaymentConstants.paymentAmount,
PaymentConstants.currencyCodeType,PaymentConstants.paymentType,
.returnURL,PaymentConstants.cancelURL,session);
return “success”;
}

public HashMap CallShortcutExpressCheckout( String paymentAmount, String currencyCodeType, String paymentType, String returnURL, String cancelURL,HttpSession session)
{
session.setAttribute(“paymentType”, paymentType);
session.setAttribute(“currencyCodeType”, currencyCodeType);

/*
Construct the parameter string that describes the PayPal payment
the varialbes were set in the web form, and the resulting string
is stored in $nvpstr
*/

String nvpstr = “&Amt=” + paymentAmount +
“&PAYMENTACTION=” +paymentType+
“&ReturnUrl=” + URLEncoder.encode( returnURL ) +
“&CANCELURL=” + URLEncoder.encode( cancelURL ) +
“&CURRENCYCODE=” + currencyCodeType;

/*
Make the call to PayPal to get the Express Checkout token
If the API call succeded, then redirect the buyer to PayPal
to begin to authorize payment. If an error occured, show the
resulting errors
*/

HashMap nvp = httpcall(“SetExpressCheckout”, nvpstr);
String strAck = nvp.get(“ACK”).toString();
if(strAck !=null && strAck.equalsIgnoreCase(“Success”))
{
session.setAttribute(“TOKEN”, nvp.get(“TOKEN”).toString());
}
return nvp;
}

public HashMap CallMarkExpressCheckout( String paymentAmount, String currencyCodeType, String paymentType, String returnURL, String cancelURL,
String shipToName, String shipToStreet, String shipToCity, String shipToState,
String shipToCountryCode, String shipToZip, String shipToStreet2, String phoneNum,
HttpSession session)
{
session.setAttribute(“paymentType”, paymentType);
session.setAttribute(“currencyCodeType”, currencyCodeType);

/*
Construct the parameter string that describes the PayPal payment
the varialbes were set in the web form, and the resulting string
is stored in $nvpstr
*/

String nvpStr = “ADDROVERRIDE=1&Amt=” + paymentAmount + “&PAYMENTACTION=” + paymentType;
nvpStr = nvpStr + “&CURRENCYCODE=” + currencyCodeType +
“&ReturnUrl=” + URLEncoder.encode( returnURL ) +
“&CANCELURL=” + URLEncoder.encode( cancelURL );
nvpStr = nvpStr + “&SHIPTONAME=” + shipToName +
“&SHIPTOSTREET=” + shipToStreet +
“&SHIPTOSTREET2=” + shipToStreet2;
nvpStr = nvpStr + “&SHIPTOCITY=” + shipToCity +
“&SHIPTOSTATE=” + shipToState +
“&SHIPTOCOUNTRYCODE=” +shipToCountryCode;
nvpStr = nvpStr + “&SHIPTOZIP=” + shipToZip +
“&PHONENUM” + phoneNum;
/*
Make the call to PayPal to set the Express Checkout token
If the API call succeded, then redirect the buyer to PayPal
to begin to authorize payment. If an error occured, show the
resulting errors
*/
HashMap nvp = httpcall(“SetExpressCheckout”, nvpStr);
String strAck = nvp.get(“ACK”).toString();
if(strAck !=null && (strAck.equalsIgnoreCase(“Success”)
||strAck.equalsIgnoreCase(“SuccessWithWarning”)))
{
session.setAttribute(“TOKEN”, nvp.get(“TOKEN”).toString());
}
return nvp;
}

public HashMap httpcall( String methodName, String nvpStr)
{
String version = “2.3”;
String respText = “”;
HashMap nvp=null;
// Enter Seller paypal account details.
String gv_APISignature = “AagAlIIxsi4TWAcTDu.FFUfJmzyAAUH7fQ3qUuhoQQ-yynHN9wgtWUuL “;
String gv_APIUserName = “jajnas_1293170638_biz_api1.gmail.com”;
String gv_BNCode = “PP-ECWizard”;
String gv_APIPassword = “1293170653”;
String gv_Version = “2.3”;
String encodedData = “METHOD=” + methodName + “&VERSION=” + PaymentConstants.gv_Version + “&PWD=” + PaymentConstants.gv_APIPassword + “&USER=” + PaymentConstants.gv_APIUserName + “&SIGNATURE=” + PaymentConstants.gv_APISignature + nvpStr + “&BUTTONSOURCE=” + PaymentConstants.gv_BNCode;

try
{
Object gv_APIEndpoint = “https://api-3t.sandbox.paypal.com/nvp”;
URL postURL = new URL( (String) gv_APIEndpoint );
HttpURLConnection conn = (HttpURLConnection)postURL.openConnection();
// Set connection parameters. We need to perform input and output,
// so set both as true.
conn.setDoInput (true);
conn.setDoOutput (true);
// Set the content type we are POSTing. We impersonate it as
// encoded form data
conn.setRequestProperty(“Content-Type“, “application/x-www-form-urlencoded“);
conn.setRequestProperty( “User-Agent“, PaymentConstants.agent );
//conn.setRequestProperty( “Coentent-Typ”, type );
conn.setRequestProperty( “Content-Length“, String.valueOf( encodedData.length()) );
conn.setRequestMethod(“POST”);
// get the output stream to POST to.
DataOutputStream output = new DataOutputStream( conn.getOutputStream());
output.writeBytes( encodedData );
output.flush();
output.close ();
// Read input from the input stream.
DataInputStream in = new DataInputStream (conn.getInputStream());
int rc = conn.getResponseCode();
if ( rc != -1)
{
BufferedReader is = new BufferedReader(new InputStreamReader( conn.getInputStream()));
String _line = null;
while(((_line = is.readLine()) !=null))
{
respText = respText + _line;
}
nvp = deformatNVP(respText );
}
return nvp;
}
catch( IOException e )
{
// handle the error here
return null;
}
}
public HashMap deformatNVP( String pPayload ) throws IOException
{
HashMap nvp = new HashMap();
StringTokenizer stTok = new StringTokenizer( pPayload, “&”);
while (stTok.hasMoreTokens())
{
StringTokenizer stInternalTokenizer = new StringTokenizer( stTok.nextToken(), “=”);
if (stInternalTokenizer.countTokens() == 2)
{
String key = URLDecoder.decode( stInternalTokenizer.nextToken());
System.out.println(“Key”+key);
String value = URLDecoder.decode( stInternalTokenizer.nextToken());
nvp.put( key.toUpperCase(), value );
if(key.equals(“TOKEN”)){
String url=”https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=”+value;
response.sendRedirect(url);
}
}
}
return nvp;
}

PaymentPostBackAction.java //call this function on-click return url from paypal

public String handleResponse() throws Exception {
InvestorDetails investorDetails = (InvestorDetails) request.getSession().getAttribute(PaymentConstants.INVESTOR_DETAILS);
UsersDetails userDetails = (UsersDetails) request.getSession().getAttribute(PaymentConstants.USER_DETAILS);
User user=(User)investorDetails;
String status = request.getParameter(“status”);
String token = request.getParameter(“token”).toString();
HashMap nvp = GetShippingDetails(token, request.getSession());
String strAck = nvp.get(“ACK”).toString();
if(strAck != null && (strAck.equalsIgnoreCase(“Success”) || strAck.equalsIgnoreCase(“SuccessWithWarning”)))
{
String email = nvp.get(“EMAIL”).toString(); // ‘ Email address of payer.
String payerId = nvp.get(“PAYERID”).toString(); // ‘ Unique PayPal customer account identification number.
String payerStatus = nvp.get(“PAYERSTATUS”).toString(); // ‘ Status of payer. Character length and limitations: 10 single-byte alphabetic characters.
String firstName = nvp.get(“FIRSTNAME”).toString(); // ‘ Payer’s first name.
String lastName = nvp.get(“LASTNAME”).toString(); // ‘ Payer’s last name.
String cntryCode = nvp.get(“COUNTRYCODE”).toString(); // ‘ Payer’s country of residence in the form of ISO standard 3166 two-character country codes.
//confirmation of payment.
HashMap nvpreturn = ConfirmPayment(PaymentConstants.paymentAmount,request.getSession(),request);
String transactionId = nvpreturn.get(“TRANSACTIONID”).toString();
/*
‘ The information that is returned by the GetExpressCheckoutDetails call should be integrated by the partner into his Order Review
‘ page
*/
// Save Payment Details……..
if(nvpreturn != null){
//Long refId= null;
userService.registerUser(userDetails, investorDetails);
userService.saveRegistrationPreference(user);
UserPayment userPayment = new UserPayment();
userPayment.setRefno(String.valueOf(payerId));
userPayment.setStatus(status);
userPayment.setUppTransactionId(transactionId);// place of transactionId
userPayment.setUser(user);
userService.saveUserPaymentDetails(userPayment);
}
}
else
{
// Display a user friendly Error on the page using any of the following error information returned by PayPal
String ErrorCode = nvp.get(“L_ERRORCODE0”).toString();
String ErrorShortMsg = nvp.get(“L_SHORTMESSAGE0”).toString();
String ErrorLongMsg = nvp.get(“L_LONGMESSAGE0”).toString();
String ErrorSeverityCode = nvp.get(“L_SEVERITYCODE0”).toString();
request.setAttribute(“ErrorCode”, ErrorCode);
request.setAttribute(“ErrorShortMsg”, ErrorShortMsg);
request.setAttribute(“ErrorLongMsg”, ErrorLongMsg);
request.setAttribute(“ErrorSeverityCode”, ErrorSeverityCode);
userService.savePaymentFailureLog(user,token,”failure”);
return “failure”;
}
request.getSession().removeAttribute(PaymentConstants.INVESTOR_DETAILS);
request.getSession().removeAttribute(PaymentConstants.USER_DETAILS);
return “success”;
}
public HashMap ConfirmPayment( String finalPaymentAmount, HttpSession session, HttpServletRequest request)
{

/*’—————————————————————————-
‘—- Use the values stored in the session from the previous SetEC call
‘—————————————————————————-
*/
String token = session.getAttribute(“TOKEN”).toString();
String currencyCodeType = session.getAttribute(“currencyCodeType”).toString();
String paymentType = session.getAttribute(“paymentType”).toString();
String payerID = session.getAttribute(“PAYERID”).toString();
String serverName = request.getServerName();

String nvpstr = “&TOKEN=” + token + “&PAYERID=” + payerID + “&PAYMENTACTION=” + paymentType + “&AMT=” + finalPaymentAmount;
nvpstr = nvpstr + “&CURRENCYCODE=” + currencyCodeType + “&IPADDRESS=” + serverName;

/*Make the call to PayPal to finalize payment
If an error occured, show the resulting errors*/

HashMap nvp = httpcall(“DoExpressCheckoutPayment”, nvpstr);
return nvp;
}
public HashMap GetShippingDetails( String token, HttpSession session)
{
/*
Build a second API request to PayPal, using the token as the
ID to get the details on the payment authorization
*/

String nvpstr= “&TOKEN=” + token;

/*
Make the API call and store the results in an array. If the
call was a success, show the authorization details, and provide
an action to complete the payment. If failed, show the error
*/

HashMap nvp = httpcall(“GetExpressCheckoutDetails”, nvpstr);
String strAck = nvp.get(“ACK”).toString();
if(strAck !=null && (strAck.equalsIgnoreCase(“Success”) || strAck.equalsIgnoreCase(“SuccessWithWarning”)))
{
session.setAttribute(“PAYERID”, nvp.get(“PAYERID”).toString());
}
return nvp;
}

public HashMap httpcall( String methodName, String nvpStr)
{
String version = “2.3”;
String respText = “”;
HashMap nvp=null;
// enter Seller paypal account details.
String gv_APISignature = “AagAlIIxsi4TWAcTDu.FFUfJmzyAAUH7fQ3qUuhoQQ-yynHN9wgtWUuL “;
String gv_APIUserName = “jajnas_1293170638_biz_api1.gmail.com”;
String gv_BNCode = “PP-ECWizard”;
String gv_APIPassword = “1293170653”;
String gv_Version = “2.3”;
String encodedData = “METHOD=” + methodName + “&VERSION=” + PaymentConstants.gv_Version + “&PWD=” + PaymentConstants.gv_APIPassword + “&USER=” + PaymentConstants.gv_APIUserName + “&SIGNATURE=” + PaymentConstants.gv_APISignature + nvpStr + “&BUTTONSOURCE=” + PaymentConstants.gv_BNCode;

try
{
Object gv_APIEndpoint = “https://api-3t.sandbox.paypal.com/nvp”;
URL postURL = new URL( (String) gv_APIEndpoint );
HttpURLConnection conn = (HttpURLConnection)postURL.openConnection();

// Set connection parameters. We need to perform input and output,
// so set both as true.
conn.setDoInput (true);
conn.setDoOutput (true);

// Set the content type we are POSTing. We impersonate it as
// encoded form data
conn.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);
conn.setRequestProperty( “User-Agent”,PaymentConstants.agent );

//conn.setRequestProperty( “Content-Type”, type );
conn.setRequestProperty( “Content-Length”, String.valueOf( encodedData.length()) );
conn.setRequestMethod(“POST”);
// get the output stream to POST to.
DataOutputStream output = new DataOutputStream( conn.getOutputStream());
output.writeBytes( encodedData );
output.flush();
output.close ();
// Read input from the input stream.
DataInputStream in = new DataInputStream (conn.getInputStream());
int rc = conn.getResponseCode();
if ( rc != -1)
{
BufferedReader is = new BufferedReader(new InputStreamReader( conn.getInputStream()));
String _line = null;
while(((_line = is.readLine()) !=null))
{
respText = respText + _line;
}
nvp = deformatNVP( respText );
}
return nvp;
}
catch( IOException e )
{
// handle the error here
return null;
}
}
@SuppressWarnings(“unchecked”)
public HashMap deformatNVP( String pPayload ) throws IOException
{
HashMap nvp = new HashMap();
StringTokenizer stTok = new StringTokenizer( pPayload, “&”);
while (stTok.hasMoreTokens())
{
StringTokenizer stInternalTokenizer = new StringTokenizer( stTok.nextToken(), “=”);
if (stInternalTokenizer.countTokens() == 2)
{
String key = URLDecoder.decode( stInternalTokenizer.nextToken());
System.out.println(“Key”+key);
String value = URLDecoder.decode( stInternalTokenizer.nextToken());
nvp.put( key.toUpperCase(), value );
}
}
return nvp;
}
//End

Paypal Test account: //This is for testing the paypal payment while creating the test account for buyer as well as seller.

1. create paypal account: https://developer.paypal.com/ sign Up Now
2. click on “Test Account”: choose-> New test account: Preconfigured <-|
// create two account one for seller and one for buyer.
(Note: while creating the account note down the password and username.)

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 25,000 views in 2012. If each view were a film, this blog would power 6 Film Festivals

Click here to see the complete report.

for loop diagram

Here i attached a java example to show how to check duplicated value in an array. I show two methods to implement this.

1) Using two for loop to compare each values in array – Line 21

2)Using HashSet to detect duplicated value. – Line 40

Hope help, if you know any other method to compare duplicated value in array, please share it to me.

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
 
package com.mkyong;

import java.util.Set;
import java.util.HashSet;

public class CheckDuplicate
{
	public static void main(String args[])
	{
		String [] sValue = new String[]{"a","b","c","d","","","e","a"};

		if(checkDuplicated_withNormal(sValue))
			System.out.println("Check Normal : Value duplicated! \n");
		if(checkDuplicated_withSet(sValue))
			System.out.println("Check Set : Value duplicated! \n");

	}

	//check duplicated value
	private static boolean checkDuplicated_withNormal(String[] sValueTemp)
	{
		for (int i = 0; i < sValueTemp.length; i++) {
			String sValueToCheck = sValueTemp[i];
			if(sValueToCheck==null || sValueToCheck.equals(""))continue; //empty ignore
			for (int j = 0; j < sValueTemp.length; j++) {
					if(i==j)continue; //same line ignore
					String sValueToCompare = sValueTemp[j];
					if (sValueToCheck.equals(sValueToCompare)){
							return true;
					}
			}

		}
		return false;

	}

	//check duplicated value
	private static boolean checkDuplicated_withSet(String[] sValueTemp)
	{
		Set<String> sValueSet = new HashSet<String>();
		for(String tempValueSet : sValueTemp)
		{
			if (sValueSet.contains(tempValueSet))
				return true;
			else
				if(!tempValueSet.equals(""))
					sValueSet.add(tempValueSet);
		}
		return false;
	}}

5 Examples of when to use silence ?

Posted: January 27, 2012 in Random Posts
Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

1. During arguments. One of the best times to use the power of silence is during  an argument is to stay silent. The ego will be trying to force its way out of you and finish the argument but you are the controller, not the ego. When someone is shouting at you, looking for an argument or just picking on you can literally take all the power away from them and keep all your energy by simply looking at them and saying absolutely nothing. This is extremely difficult to do but very powerful.

2. Gossiping. When there is a crowd of people in the workplace there are gossipers who speak about other people. The thing with gossiping is that it is contagious. When we don’t like someone and someone else starts speaking about them we naturally tend to voice our opinion, I’ve done it lots of times and have to stop myself.

Try and stop yourself from catching the virus of gossiping and use the power of silent whenever it occurs. If you are a gossiper yourself and people around start to notice that you are ‘not your usual self’, don’t give an explanation just leave saying you’ve got work to do or whatever, pretty soon you’ll be out of the gossiping loop.

3. When someone is talking. Silence is a great tool for counselors if used in the right way. It’s also great when listening to friends and family.

Just let people talk and listen to them and use your facial expressions and movements to acknowledge that you are listening. This can be a tough thing to do but extremely powerful for both you, as the listener, and the talker.

You will find that as you practice this, more people come to talk to you as you will be known as a listener. Obviously there are times to speak during the conversation, however when you do, make sure it is to paraphrase what the talker is saying or asking questions to get more information, don’t make it about yourself.

When people want to know more about you they will ask you questions, this is the time to talk about yourself but always have the listener be part of the conversation.

4. When the house is empty. The silence of the home can be quite disturbing to some people as there is a natural need to fill the void of silence. We turn on the radio, play some music, call friends or family, or turn on the TV to fill this void. Having a completely silent home when you are alone does not mean you are alone it simply means you are recharging your mind and giving it some downtime.

Silence helps us to work through, in our minds, the events of the day or project what we want to happen during the day ahead. I am a night owl and also a morning lark. I love the silence when I know everyone is safe and tucked up in bed and I can write or work on the computer. At the weekends I go to bed with my wife to talk about days events or our plans and just have a laugh or whatever. My wife, who loves her sleep, has gone to sleep I kiss her goodnight and get up for a few hours to write as this is the time I am most inspired. I am also the first person up in the morning which means I have another 2 hours to write or work on my online projects.

I know it’s harder when you are alone, however silent time can be used to think about the life you want and work out ways to get it.

5. Quiet reflection. This is a fantastic way to connect with world in a way that is not possible when you are surrounded by hubbub noise. 15 minutes in the morning, 15 minutes in the evening simply focusing on your breath can do wonders for both mind and body. I truly believe that with practice quiet reflection can help us reach a level of deep inner calm.

The state of silence is a way of reaching another part of your mind not possible when going about your daily routine. This other part of your mind is connected in every way to the world around you and with practice you can tap into this knowledge.