iOS Question b4i and Paypal

MarcoRome

Expert
Licensed User
Longtime User
This library is excellent but can only be used in some countries (USA, Australia, UK, if I remember correctly).
You could in any case for both (B4A / B4i) create a html page like this.

upload_2018-3-1_5-22-37.png


This is code:

B4X:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

  <!-- Identify your business so that you can collect the payments. -->
  <input type="hidden" name="business" value="[email protected]">

  <!-- Specify a Buy Now button. -->
  <input type="hidden" name="cmd" value="_xclick">

  <!-- Specify details about the item that buyers will purchase. -->
  <input type="hidden" name="item_name" value="Hot Sauce-12oz. Bottle">
  <input type="hidden" name="amount" value="5.95">
  <input type="hidden" name="currency_code" value="USD">

  <!-- Display the payment button. -->
  <input type="image" name="submit" border="0"
  src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png"
  alt="Buy Now">
  <img alt="" border="0" width="1" height="1"
  src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >

</form>

the thing to understand and if it is successful (it should redirect to a page and return a value)
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Thanks MarcoRome, but I don't understand....
My B4A or B4I app have an html code?
This page seems to be for a credit card... For Paypal I need only email and password.
And how I understand if it is successful?
I'm Marco and I'm from Rome too, un contatto romano diretto potrebbe essere utile.
Posso cercarti al telefono che è sul tuo sito?
Grazie
Marco
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
What does Apple says when he realizes you are getting money outside the mechanism of In-App-Purchase ?
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
ok, using webview i called Paypal and i have done a payment. (I used Paypal Sandpbox for testing)
Now I want capture Paypal answer (payment accepted or rejected) and return this information to my App.
How can i do it?
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
This link have many answers and is written for a web page.
How have I to implement IPN code on My App?
Have an example?
Auto Return is turned off by default. To turn on Auto Return:

  1. Log in to your PayPal account at https://www.paypal.com. The My Account Overview page appears.
  2. Click the Profile subtab. The Profile Summary page appears.
  3. Click the My Selling Tools link in the left column.
  4. Under the Selling Online section, click the Update link in the row for Website Preferences. The Website Payment Preferences page appears
  5. Under Auto Return for Website Payments, click the On radio button to enable Auto Return.
  6. In the Return URL field, enter the URL to which you want your payers redirected after they complete their payments. NOTE: PayPal checks the Return URL that you enter. If the URL is not properly formatted or cannot be validated, PayPal will not activate Auto Return.
  7. Scroll to the bottom of the page, and click the Save button.
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
thanks. I read these instructions (that are possible only on business account and not on sandbox account).
Then there is IPN code:

<?php
// Check to see there are posted variables coming into the script
if ($_SERVER['REQUEST_METHOD'] != "POST")
die("No Post Variables");
// Initialize the $req variable and add CMD key value pair
$req = 'cmd=_notify-validate';
// Read the post from PayPal
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// Now Post all of that back to PayPal's server using curl, and validate everything with PayPal
// We will use CURL instead of PHP for this for a more universally operable script (fsockopen has issues on some environments)
//$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$url = "https://www.paypal.com/cgi-bin/webscr";
$curl_result = $curl_err = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);

$req = str_replace("&", "\n", $req); // Make it a nice list in case we want to email it to ourselves for reporting
// Check that the result verifies
if (strpos($curl_result, "VERIFIED") !== false) {
$req .= "\n\nPaypal Verified OK";
} else {
$req .= "\n\nData NOT verified from Paypal!";
mail("[email protected]", "IPN interaction not verified", "$req", "From: [email protected]");
exit();
}

/* CHECK THESE 4 THINGS BEFORE PROCESSING THE TRANSACTION, HANDLE THEM AS YOU WISH
1. Make sure that business email returned is your business email
2. Make sure that the transaction�s payment status is �completed�
3. Make sure there are no duplicate txn_id
4. Make sure the payment amount matches what you charge for items. (Defeat Price-Jacking) */

// Check Number 1 ------------------------------------------------------------------------------------------------------------
$receiver_email = $_POST['receiver_email'];
if ($receiver_email != "[email protected]") {
//handle the wrong business url
exit(); // exit script
}
// Check number 2 ------------------------------------------------------------------------------------------------------------
if ($_POST['payment_status'] != "Completed") {
// Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete
}

// Check number 3 ------------------------------------------------------------------------------------------------------------
$this_txn = $_POST['txn_id'];
//check for duplicate txn_ids in the database
// Check number 4 ------------------------------------------------------------------------------------------------------------
$product_id_string = $_POST['custom'];
$product_id_string = rtrim($product_id_string, ","); // remove last comma
// Explode the string, make it an array, then query all the prices out, add them up, and make sure they match the payment_gross amount
// END ALL SECURITY CHECKS NOW IN THE DATABASE IT GOES ------------------------------------
////////////////////////////////////////////////////
// Homework - Examples of assigning local variables from the POST variables
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$custom = $_POST['custom'];
// Place the transaction into the database
// Mail yourself the details
mail("[email protected]", "NORMAL IPN RESULT YAY MONEY!", $req, "From: [email protected]");
?>

How I have to use this code?
And if I haven't to use this code, how can I capture paypal answer from the app?
 
Upvote 0

Angel Garcia

Member
Licensed User
Hi All,
I know this is an old thread, but i'm facing this same issue.
I've seen on other posts that the right way to go is with braintree.
I have already followed this PayPal tutorials with express checkout (already registered a business account etc).:
https://developer.paypal.com/docs/accept-payments/express-checkout/ec-braintree-sdk/get-started/
https://developer.paypal.com/docs/a...t/ec-braintree-sdk/client-side/javascript/v3/
https://developer.paypal.com/docs/a...checkout/ec-braintree-sdk/server-side/dotnet/
But can't find the reference to pass the credit card info from the client to the server.
So my question is, what is the difference between this web method, and the braintree?
This one seems to be to much simplier, but dont know if this is the right way to go.
Many thanks in advance
 
Upvote 0

Angel Garcia

Member
Licensed User
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<!-- Identify your business so that you can collect the payments. -->
<input
type="hidden" name="business" value="[email protected]">

<!-- Specify a Buy Now
button. -->
<input
type="hidden" name="cmd" value="_xclick">

<!-- Specify details about the item that buyers will
purchase. -->
<input
type="hidden" name="item_name" value="Hot Sauce-12oz. Bottle">
<input
type="hidden" name="amount" value="5.95">
<input
type="hidden" name="currency_code" value="USD">

<!-- Display the payment
button. -->
<input
type="image" name="submit" border="0"
src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png"
alt="Buy Now">
<img alt=
"" border="0" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >

</
form>

I have tried this code in the WebView B4A and only shows for PayPal payment with an email and password, what about the credit card payment??
I thought it would show like in a regular browser with all the credit card payment option.
 
Upvote 0

potman100

Active Member
Licensed User
Longtime User
I know this is a little old, but I find creating a payment button in Paypal you can then use the email html generated link to launch the browser
and by adding the "&custom=" to the url you can send info with the payment that you need to process the payment.

The issue then is the ipn data from paypal, I use a webserver to process the ipn data, and update the database, you could easily make the app wait
till the payment on paypal is complete, ,and the ipn has been processed.

The other advantage to this method you can create a subscription button and it works the same way.

Potman100
 
Upvote 0
Top