PayPal MPL library

Pablo Torres

Active Member
Licensed User
Longtime User
Ok, let me think if I understand what you said, in my regular paypal account, I go to my account details and take note of my Id account ... and that is the ID i have to use when I ask for a payment! is that correct?
 

GMan

Well-Known Member
Licensed User
Longtime User
What if I made the payment from a different account?
???
You have to use another account to make a payment to you, 'cause you can't pay yourself.

Sorry, didnt read NJDudes post.
If you use another account it works (should)
 

GMan

Well-Known Member
Licensed User
Longtime User
Yes - simple try it.
If it works the button will appear
 

Pablo Torres

Active Member
Licensed User
Longtime User
Still not working, I dont understand what went wrong
I changed the email for mine, I changed true for false in the sandbox boolean, I even put my ID (the one I get in patpal website) in that part, but button still doesn't show, what am I missing?
 

GMan

Well-Known Member
Licensed User
Longtime User
I really dont know what could be wrong - did you posted the used code already ?
What device and what OS version you are using ?
 

Pablo Torres

Active Member
Licensed User
Longtime User
Code:

#Region Project Attributes
#ApplicationLabel: Paypal
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
Dim pp As PayPal
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
pp.Initialize("APP-XXXXXXXXXXX", False, "paypal")
ProgressDialogShow("Esperando que aparezca el botón de Paypal...")
End Sub


Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
Activity.Finish
End Sub

Sub PayPal_Ready (Success As Boolean)
Log("Listo: " & Success)
If Success Then
Activity.AddView(pp.GetPayPalButton(False), 0, 0, 200dip, 100dip)
ProgressDialogHide
End If
End Sub

Sub PayPal_Click
pp.RequestPayment("USD", 5, "pablotorres1979@yahoo.com", "CRONOS", pp.PAYMENT_TYPE_PERSONAL)
End Sub

Sub PayPal_Result (Success As Boolean, Extra As String)
Log("Finalizado: " & Success & ", Extra: " & Extra)
End Sub

Device:
Samsung S4 mini, android 4.2.2
 
Last edited:

GMan

Well-Known Member
Licensed User
Longtime User
IMHO i found the mistake:

in the GoingLive-TuT is written:
Important! Before registering your PayPal application, make sure the status of the PayPal account used to submit the application is verified.
as Pablo wrote he created a new account after having 1st problems - so is this new one also verified ? As we know it leasts some days to give Paypal time to send the verification "money" value.

As i was using still verified accounts i never had a look at this point.

Also the key looks different to the one i used:
B4X:
pp.Initialize("APP-12345678901234567", False, "Paypal")
 
Last edited:

Pablo Torres

Active Member
Licensed User
Longtime User
Yes, I read the documentation and I realized that I need to create a key for each app.
I did it and now the problem is solved.
Thanks to all
 

bluedude

Well-Known Member
Licensed User
Longtime User
Erel,

Could you release the sourcecode for this wrapper so that we could try to create a new version for the new PayPal sdk?

Cheers.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
package anywheresoftware.b4a.paypal;

import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.util.ArrayList;

import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalActivity;
import com.paypal.android.MEP.PayPalPayment;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.IOnActivityResult;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.keywords.Common;
import anywheresoftware.b4a.objects.ViewWrapper;

@Version(1.0f)
@Permissions(values={"android.permission.INTERNET", "android.permission.READ_PHONE_STATE", "android.permission.ACCESS_WIFI_STATE"})
@DependsOn(values={"PayPal_MPL"})
@ShortName("PayPal")
@ActivityObject
@Events(values={"Ready (Success As Boolean)", "Result (Success As Boolean, Extra As String)", "Click"})
public class PayPalWrapper {
   public static final int PAYMENT_TYPE_GOODS = 0;
   public static final int PAYMENT_TYPE_SERVICE = 1;
   public static final int PAYMENT_TYPE_PERSONAL = 2;
   public static final int PAYMENT_TYPE_NONE = 3;
   
   private static IOnActivityResult ion;
   private String eventName;
   private ArrayList<CheckoutButton> buttons = new ArrayList<CheckoutButton>();
   /**
    * Initializes the PayPal object. The Ready event will be raised when the service is ready.
    *AppId - PayPal app id.
    *Sandbox - Whether to run in sandbox mode.
    *EventName - Sets the subs that will handle the events.
    */
   public void Initialize(final BA ba,final String AppId,final boolean Sandbox,final String EventName) {
     eventName = EventName.toLowerCase(BA.cul);
     Runnable r = new Runnable() {

       @Override
       public void run() {
         try {
           if (PayPal.getInstance() == null) {
             PayPal pp;
             pp = PayPal.initWithAppID(ba.context, AppId, Sandbox ? PayPal.ENV_SANDBOX : PayPal.ENV_LIVE);
             pp.setLanguage("en_US");
           }
           ba.raiseEventFromDifferentThread(PayPalWrapper.this, null, 0, eventName + "_ready", false,
               new Object[] {PayPal.getInstance().isLibraryInitialized()});
         } catch (Exception e) {
           BA.printException(e, true);
           ba.raiseEventFromDifferentThread(PayPalWrapper.this, null, 0, eventName + "_ready", false,
               new Object[] {false});
         }

       }

     };
     ba.submitRunnable(r, null, 0);

   }
   /**
    * Gets the PayPal button.
    *Donate - Whether to show a Donate button or Pay button.
    */
   public View GetPayPalButton(final BA ba, boolean Donate) {
     final CheckoutButton v = PayPal.getInstance().getCheckoutButton(ba.activity, PayPal.BUTTON_278x43, Donate ?
         CheckoutButton.TEXT_DONATE : CheckoutButton.TEXT_PAY);
     v.setOnClickListener(new View.OnClickListener() {

       @Override
       public void onClick(View arg0) {
         ba.raiseEvent(PayPalWrapper.this, eventName + "_click");
       }

     });
     buttons.add(v);
     return v;
   }
   /**
    * Makes a payment request.
    *The Result event will be raised after the payment is processed.
    *Currency - 3 characters currency code.
    *Total - Payment amount.
    *Recipient - Recipient email address.
    *MerchantName - Merchant name.
    *PaymentType - One of the PAYMENT_TYPE constants.
    */
   public void RequestPayment(BA ba, String Currency, String Total, String Recipient, String MerchantName, int PaymentType) {
     for (CheckoutButton cb : buttons) {
       cb.updateButton();
     }
     PayPalPayment pay = new PayPalPayment();
     pay.setSubtotal(new BigDecimal(Total));
     pay.setCurrencyType(Currency);
     pay.setRecipient(Recipient);
     pay.setPaymentType(PaymentType);
     pay.setMerchantName(MerchantName);
     final BA processBA = ba.processBA;
     ion = new IOnActivityResult() {

       @Override
       public void ResultArrived(int resultCode, Intent intent) {
         String extra = "";
         boolean success = false;
         switch (resultCode) {
         case Activity.RESULT_OK:
           success = true;
           extra = intent.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
           break;

         case Activity.RESULT_CANCELED:
           extra = "canceled";
           break;
         case PayPalActivity.RESULT_FAILURE:
           String errorID =
             intent.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
           String errorMessage =
             intent.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
           extra = errorID + ": " + errorMessage;
         }
         processBA.raiseEvent(PayPalWrapper.this, eventName + "_result", success, extra);
       }

     };
     Intent ppIntent = PayPal.getInstance().checkout(pay, ba.context);
     ba.startActivityForResult(ion, ppIntent);
   }
}
 

bluedude

Well-Known Member
Licensed User
Longtime User
Thanks for the sourcecode. Do you think this can easily be rewritten with AdditionalJar and Java object?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…