Beta PayPal Android SDK - Wrapper - BETATESTER WANTED

DonManfred

Expert
Licensed User
Longtime User
Hallo everybody,

i want to search for some people who wants to help to develop a new library for B4A which should wrap the Android SDK from Paypal.

Actually i just build the library with some hardcoded info to imitate the "Make your first call" tutorial from Paypal

See the result-video running this B4A-Code

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pp As Paypal
    Dim ppClientID As String = "xxxxx_CFEUvb_xGkJziy-UzOW9VJ2f1gbjC111gnyNhHq"
    Dim ppSecret As String = "xxxxx_Nc5sqPjn2pcBUaD5awwioTSGZAkpTCLpmSE5qkTCvLfMB"
    Dim ppMerchant As String = "DonManfred"
    Dim ppPrivaryURL As String = "http://paypal.basic4android.de/"
    Dim ppAgreementURL As String = "http://paypal.basic4android.de/"
    Private pplogo As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    pp.Initialize("Paypal",ppClientID,ppSecret,ppMerchant,ppPrivaryURL,ppAgreementURL)
End Sub
Sub Activity_Resume
    pp.StartSvc
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    pp.StopSvc
End Sub
Sub Paypal_PaymentResult (resultCode As Int, result As String, payment As String)
    Log("Paypal_PaymentResult ("&resultCode&", "&result&","&payment&")")
    Dim parser As JSONParser
    parser.Initialize(result)
    Dim root As Map = parser.NextObject
  
    Dim response As Map = root.Get("response")
    Dim id As String = response.Get("id")
    Dim state As String = response.Get("state")
    Dim create_time As String = response.Get("create_time")
    Dim Intenttype As String = response.Get("intent")
  
    Dim response_type As String = root.Get("response_type")
    Dim client As Map = root.Get("client")
    Dim platform As String = client.Get("platform")
    Dim environment As String = client.Get("environment")
    Dim product_name As String = client.Get("product_name")
    Dim paypal_sdk_version As String = client.Get("paypal_sdk_version")

End Sub

Sub pplogo_Click
    pp.NewPayment("0.10","EUR","Brand new jeans","12345",True)
End Sub


** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Activity.RESULT_OK =-1
Paypal_PaymentResult (-1, {
"client": {
"environment": "mock",
"paypal_sdk_version": "2.8.2",
"platform": "Android",
"product_name": "PayPal-Android-SDK"
},
"response": {
"create_time": "2014-07-18T18:46:55Z",
"id": "PAY-6PU626847B294842SKPEWXHY",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
},{
"amount": "0.10",
"currency_code": "EUR",
"short_description": "Brand new jeans",
"intent": "sale"
})
** Activity (main) Resume **
 

DonManfred

Expert
Licensed User
Longtime User
Preparing B4A to use the Paypal android SDK

Go to PayPal Mobile SDKs and download the Android SDK. Download the zip and extract the zip. Copy the PayPalAndroidSDK-2.8.2.jar from the libs folder to your Additional libs folder.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
2. Setting up your B4A project

You need to add some things to the manifest-editor

B4X:
AddPermission(android.permission.CAMERA)
AddPermission(android.permission.VIBRATE)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddManifestText(
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddApplicationText(
<service android:name="com.paypal.android.sdk.payments.PayPalService"
        android:exported="false" />
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
<activity android:name="com.paypal.android.sdk.payments.LoginActivity" />
<activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" />
<activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" />
<activity android:name="io.card.payment.CardIOActivity"
          android:configChanges="keyboardHidden|orientation" />
<activity android:name="io.card.payment.DataEntryActivity" />)

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pp As Paypal
    Dim ppClientID As String = "<your apps Client ID>"
    Dim ppSecret As String = "<your apps Client Secret>"
    Dim ppMerchant As String = "<merchantname>"
    Dim ppPrivacyURL As String = "http://domain.tld/pricacypage.html"
    Dim ppAgreementURL As String = "http://domain.tld/agreementpage.html"
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
	' Initialize the Library in TESTMODE (NO NETWORK)
	pp.Initialize("Paypal",ppClientID,ppSecret,ppMerchant,ppPrivaryURL,ppAgreementURL,"MOCK")
	'
	' OR initialize the Library in SANDBOX 
	'pp.Initialize("Paypal",ppClientID,ppSecret,ppMerchant,ppPrivaryURL,ppAgreementURL,"SANDBOX")
	'
	' OR initialize the library in PRODUCTION mode (live)
	'pp.Initialize("Paypal",ppClientID,ppSecret,ppMerchant,ppPrivaryURL,ppAgreementURL,"SANDBOX")
End Sub
Sub Activity_Resume
    ' On resume the Paypal Service must be started
    pp.StartSvc
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    ' On pause the Paypal Service must be stoppted
    pp.StopSvc
End Sub
Sub Paypal_PaymentResult (resultCode As Int, result As String, payment As String)
    Log("Paypal_PaymentResult ("&resultCode&", "&result&","&payment&")")
    Dim parser As JSONParser
    parser.Initialize(result)
    Dim root As Map = parser.NextObject
  
    Dim response As Map = root.Get("response")
    Dim id As String = response.Get("id")
    Dim state As String = response.Get("state")
    Dim create_time As String = response.Get("create_time")
    Dim Intenttype As String = response.Get("intent")
  
    Dim response_type As String = root.Get("response_type")
    Dim client As Map = root.Get("client")
    Dim platform As String = client.Get("platform")
    Dim environment As String = client.Get("environment")
    Dim product_name As String = client.Get("product_name")
    Dim paypal_sdk_version As String = client.Get("paypal_sdk_version")
End Sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
3. Starting a Payment-Request

In my examplevideo in Post #1 i used a Image. On Image click i started a new payment...

You can start a new pyment with

B4X:
pp.NewPayment("0.10","EUR","Brand new jeans","12345",True)
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Creating a PayPal app and getting the login credentials

Navigate to the My REST apps page, and log in if necessary. Click Create App to begin the application-creation process.

When you create a new app, PayPal generates a set of Sandbox OAuth keys for the application (the keys consist of a client_id and secret). See Manage your applications for details on creating and managing your PayPal applications.

Tip: See how the OAuth keys work by running the example in the next step—the example uses a set of dummy keys so you can easily make your first call by pasting the example as-is into a terminal window.


Write down the Client ID and Secret as you need them later in your B4A project
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Paypal
Version:
0.07
  • Paypal
    Events:
    • PaymentResult (resultCode As Int, result As String, payment As String)
    Methods:
    • Initialize (EventName As String, clientid As String, Secret As String, merchantName As String, PrivacyUri As String, AgreementUri As String)
      Initialize the Paypal-Library
      Parameter
      String EventName
      String clientid
      String Secret
      String merchantName
      String PrivacyUri
      String AgreementUri
    • NewPayment (sum As String, currency As String, article As String, invoiceNo As String, enableShippingAddressesRetrieval As Boolean)
      NewPayMent starts a new payment
      Parameters
      String sum
      String currency
      String article
      String invoiceNo
      boolean enableShippingAddressesRetrieval
    • StartSvc
    • StopSvc
    • clearShippingAddress
      Clears a shippingaddress which will be used in a payment
    • setShippingAddress (recipient As String, line1 As String, city As String, state As String, postalCode As String, countryCode As String)
      Add app-provided shipping address to payment
      Parameters
      String recipient
      String line1
      String city
      String state
      String postalCode
      String countrycode
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.CAMERA
    • android.permission.INTERNET
    • android.permission.VIBRATE
 
Last edited:
Upvote 0

ktlua

Member
Licensed User
Preparing B4A to use the Paypal android SDK

Go to PayPal Mobile SDKs and download the Android SDK. Download the zip and extract the zip. Copy the PayPalAndroidSDK-2.8.2.jar from the libs folder to your Additional libs folder.

I followed your link and clicked Android SDK. I downloaded the PayPalAndroidSDK-2.15.1.aar
PayPalAndroidSDK-2.15.1.aar

but not the jar file. Kindly let me know how to get the jar file from the aar file?

Thanks!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Kindly let me know how to get the jar file from the aar file?
You can try:
- Rename the .aar to .zip
- open the zip
- Extract the file classes.jar
- rename the classes.jar to PayPalAndroidSDK-2.15.1.jar
- edit the library xml and change the DependsOn-Line at the end to match PayPalAndroidSDK-2.15.1.jar

Try to use... If the new version is compatible it could work...

Did not try by myself
 
Upvote 0

ktlua

Member
Licensed User
Thank you very much.

I just received this info from PayPal:

"The MPL uses Adaptive payments API which is currently in a limited release and on path to be deprecated hence our recommendation will be to use Braintree mobile integration."

My choice now is only limited to the use of Android Studio for my development as I do not know how to wrap their client SDK for my application.
 
Upvote 0
Top