Showing posts with label free mobile theams. Show all posts
Showing posts with label free mobile theams. Show all posts

Wednesday, April 13, 2011

Adding PayPal payment in Android Application

Hi everyone

We all know PayPal is mostly using for transaction in recent days. The following is explain you how to add PayPal payment from your android application

Ready to get started with a simple payment? These steps will walk you through integrating the PayPal library and submitting it to x.com
Step 1 – Set up your sandbox accounts if you haven't already. You can create sandbox accounts by going to developer.paypal.com.
Step 2 – Add the PayPal library (a .jar file) into your Eclipse project, and then add the jar file to the build path. You can right click on the jar file to do this.
Step 3 – Update the AndroidManifest. The manifest will need to include the new activity "com.paypal.android.MEP.PayPalActivity". It will also need to declare the two permissions for Internet and Read-Phone-State.

Code:



<activity android:name="com.paypal.android.MEP.PayPalActivity"

 android:theme="@android:style/Theme.Translucent.NoTitleBar"

 android:configChanges="keyboardHidden|orientation/>

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>




Step 4 – Import the classes. Open the java file where you are adding the PayPal functionality. You will need to declare the various PayPal classes to use in your project.
Import com.paypal.android.CheckoutButton

Code:



import com.paypal.android.MEP.PayPal;

import com.paypal.android.MEP.PayPalActivity;

import com.paypal.android.MEP.PayPalPayment;

import com.paypal.android.MEP.PayPalAdvancedPayment;

import com.paypal.android.MEP.PayPalInvoiceData;

import com.paypal.android.MEP.PayPalInvoiceItem;

import com.paypal.android.MEP.PayPalReceiverDetails;




Step 5 – Initialize the library by using the initWithAppId method. You'll pass in your App ID and the environment. The environment can either point to Live, Sandbox, or None. The "None" environment puts the library in a demo mode which makes no server calls so that you can continue coding even if you don't have a connection. You can also set the language here.

Code:

PayPal pp = PayPal.initWithAppID(this, "APP-80W284485P519543T", PayPal.ENV_SANDBOX); 




Step 6 – Place a PayPal button on the screen. You can choose from several different button sizes in the integration guide. You'll also pass the type of payment (hard goods, service, donation, personal payment). Then set the onClick listener for the button.
Code:



LinearLayout layoutSimplePayment = new LinearLayout(this);

layoutSimplePayment.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,

    LayoutParams.WRAP_CONTENT));

layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);

CheckoutButton launchSimplePayment = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY);

launchSimplePayment.setOnClickListener(this);

layoutSimplePayment.addView(launchSimplePayment);

content.addView(layoutSimplePayment);



Step 7 – Implement the onClick function. This is where the actual checkout call happens. You'll specify all of the payment parameters (amount, currency, tax, shipping, recipient's email). You can also use some optional methods to recalculate the amount based on an address. You'll then create a new intent based on the PayPalActivity class and add the payment you just created.
Code:


Public void onClick (View v) {

PayPalPayment payment = new PayPalPayment();

payment.setSubtotal(new BigDecimal("8.25"));

payment.setCurrencyType("USD");

payment.setRecipient("bike-store-sandbox@gmail.com");

payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);

Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);

startActivityForResult(checkoutIntent, 1);




Step 8 – Handle the response. You will receive the results through the onActivityResult method. It will either return OK, Cancelled, or Failure based on how the payment ended. When you receive these calls, you can continue in your app by thanking the buyer or asking them to try later.

Code:


@Override

public void onActivityResults(int requestCode, int resultCode, Intent data) {

   switch(resultCode) {

      case Activity.RESULT_OK:

          break;

       case Activity.RESULT_CANCELED:

           break;

       case PayPalActivity.RESULT_FAILURE:

  }

}



Step 9 – Complete your project. Once you've finished your application, you can submit it to x.com (under the "My Apps" tab). In order for us to test it, you will need to attach a .zip file containing your .apk. PayPal will review the app in 1 business day (for apps using simple payments) and send you a valid App ID for the live environment. You"ll just need to update init method to point to Live with this new ID. (Don't forget to update the recipient to your live email address).



To read more click Here

Thursday, January 20, 2011

Creating a jar File in Eclipse


To create a new JAR file in the workbench:
  1. Either from the context menu or from the menu bar's File menu, select Export.



     
  2. Expand the Java node and select JAR file. Click Next.



     
  3. In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.




     
  4. Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source files and resources(Note: Selected resources are exported in both cases.

    IMPORTANT: In this example the project keeps the source code in a folder named src. Your project may have a different set up. Be sure you expand the tree to show the default package and that the .java files are checked on the right. Alternatively deselect the option that says Export generated class files and resources and select the option that says Export Java source files and resources. For CS307 we want the .java files. We do not want or need the .class files. If you do not turn in your source files, the .java files, your assignment grade will be 0.



    If there are other files or resources you want to include they must be in a an open project. Browse to their location via the directory tree on the left and ensure the file or resource is checked in the window on the right. In the example below we are including a file named  OtherFile.txt which is located in the A3 directory.



     
  5. In the Select the export destination field, either type or click Browse to select a location for the JAR file.






     
  6. Select or clear the Compress the contents of the JAR file checkbox. (This option is unimportant for CS307.)
  7. Select or clear the Overwrite existing files without warning checkbox. If you clear this checkbox, then you will be prompted to confirm the replacement of each file that will be overwritten. (This option is unimportant for CS307.)
  8. You have two options:
  9. Now, navigate to the location you specified for the jar. The icon you see and the behavior you get if you double click it will vary depending on how your computer is set up.



    One easy way of checking if the jar has the correct files is to rename it with a .zip extension. Then use whatever you zip program is to look at the files inside. (This may not work depending on how your system is set up.)

    Rename to .zip extension:



    Open up with zip program / utility.



    In the above image you can see that A3.jar (renamed to A3.zip) contains 2 files MathMatrix.java and MathMatrixTester.java. Realize you may have multiple copies of those files on your computer. You can unzip the file (in a location different from where the files were originally located!!) and open the .java files to ensure they are correct or compare the size of the files to the size of the originals. Alternatively you can unjar the jar file, again in a different location that the original .java files, and check the files.

    If you changed the extension to .zip you must change it back to .jar before submitting your file via turnin.