I have to integrate PayPal payments in Flutter and the only plugin that seems to have this kind of functionality is flutter_braintree. But the documentation there is not so detailed, so I am kind of confused how to use this plugin to have real payments. My mission is to have this kind of flow: click on a PayPal button in the app and then proceed with PayPal paying to a predefined IBAN. I tried to examine the PayPal and Braintree documentations, but since there is nothing mentioned for Flutter, I am a little bit confused.
Please help me what's the right direction to go in order to fulfil my requirements. I have the following questions:
How to use this plugin and make real payments? What do I need - a client token as far as I see, but I am going to generate this in Flutter?
Where should I put the IBAN that I want the money to be transferred to?
Am I supposed to use some kind of webviews for the PayPal, or this plugin is enough?
Thank you in advance, I am really stuck on this topic and can't find a solution.
Generate clientToken in php | nodejs see: https://developers.braintreepayments.com/reference/request/client-token/generate/php
$clientToken = $gateway->clientToken()->generate([
"customerId" => '21534539348326'//create customer in panel
]);`
Generate paymentNonce in app flutter:
BraintreePayment braintreePayment = new BraintreePayment();
var data = await braintreePayment.showDropIn(
nonce: clientNonce,
amount: "2.0",
inSandbox: true,
);
print("Response of the payment $data");
// exe: Generate transaction in php | nodejs see: https://github.com/braintree/braintree_php
$result = $gateway->transaction()->sale([
'amount' => '1000.00',
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]
]);
Related
I have scoured the docs and this tutorial about 100 times but can't figure out how to go through the payment process using a PayPal account as opposed to a credit card. I have gotten the credit card payment to go through just fine.
In the aforementioned tutorial, it is stated that I am supposed to expect a JSON response from the server after making an OAuth credential:
$sdkConfig = array(
"mode" => "sandbox"
);
$cred = new OAuthTokenCredential("clientID","clientSecret", $sdkConfig);
I get absolutely no server response despite geting a '200 OK' status from the server.
Initially I had my code set up like a bunch of other tutorials:
$apiContext = new ApiContext(
new OAuthTokenCredential(
'clientID', // ClientID
'clientSecret' // ClientSecret
)
);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item1 = new Item();
$item1->setName("Donation squares.");
$item1->setCurrency('USD');
$item1->setQuantity(1);
$item1->setPrice(1);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$amountDetails = new Details();
$amountDetails->setSubtotal('7.41');
$amountDetails->setTax('0.03');
$amountDetails->setShipping('0.03');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$amount->setDetails($amountDetails);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("https://devtools-paypal.com/guide/pay_paypal/php?success=true");
$redirectUrls->setCancelUrl("https://devtools-paypal.com/guide/pay_paypal/php?cancel=true");
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try{
$payment->create($apiContext);
} catch(Exception $e){
echo $e
exit(1);
}
None of this works either - no response from the server whatsoever.
ANSWER / COMMENT
You're not supposed to be looking for a JSON response after all. If the payment is successfully created, an approval URL should be generated by running
$payment->getApprovalLink();
The user then follows this link to finalize his/her payment.
You might be interested in following a very simple instruction here at PayPal-PHP-SDK, that explains how to make calls using PayPal PHP SDK. I know you have already gone through that, and are looking for how to create a payment using PayPal.
I am not sure you are aware of this, but PayPal-PHP-SDK comes along with a lot of samples, that you could run by just one simple command (if you have PHP 5.4 or higher). One of the first sample have the instructions and code to make PayPal Call.
There are two steps involved in that.
Create a Payment. Receive a approval_url link to be used to ask the user to complete Paypal flow over any browser.
Once the user accepts the payment on paypal website, it will be redirected back to your website, where you execute the payment.
Both the code samples are provided here and here.
Let me know if this helps, and you have any more questions. I would be more than happy to help.
I use PayPal Adaptive Payments (parallel) on my website and I've encountered a strange problem with two payments in two different browser tabs from the same sender. The similar question was asked before, but nobody answered there.
The scenario which reproduces the problem
The user opens the first browser tab of the website and starts a payment process to the first seller.
PayPal's lightbox with Login button appears.
The user opens the second browser tab of the website and starts a payment process to the second seller.
Again, PyaPal's lightbox with Login button appears.
The user returns to the first browser tab and login to PayPal.
After login to PayPal in the first browser tab the user sees payment details to the second seller.
After login to PayPal in the second browser tab the user sees payment details to the second seller.
It seems that PayPal Adaptive Payments support only one transaction from one sender.
How it works
The website works with Ruby on Rails and I use paypal_adaptive gem for payments with PayPal. The payment flow is quite simple:
The user clicks on Buy button on the website. The client makes AJAX request which handled by payment controller in Ruby on Rails.
In the controller the app makes Pay request to PayPal API using paypal_adaptive gem and receives a PayKey (see the code below).
The server responds to the client with the PayKey and the client uses it in PayPal form to start payment process through PayPal's lightbox (see the code below).
That's it. After that I do not control anything (the payment process goes through PayPal's external webpage).
Additional notes
I'm sure that the data for Pay request is different on the server side in the test scenario listed above.
I've tried different PayPal's dialog options besides PayPal's lightbox: mini-browser and popup. These options doesn't affect on this bug and it is still reproducable.
The client code
<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" class="paypal-hidden-form" target="PPDGFrame">
<button id="paypal-submit"></button>
<input id="type" type="hidden" name="expType" value="light">
<!-- Insert PayKey here and click on the form's submit button using jQuery after server's response. -->
<input id="paypal-key" type="hidden" name="paykey" value="">
</form>
<!-- Paypal -->
<script type="text/javascript" charset="utf-8">
var dgFlow = new PAYPAL.apps.DGFlow({ trigger: "paypal-submit", expType: "light" });
function MyEmbeddedFlow(embeddedFlow) {
this.embeddedPPObj = embeddedFlow;
this.paymentSuccess = function(paymentStatus) {
this.embeddedPPObj.closeFlow();
// More UI code here...
};
this.paymentCanceled = function() {
this.embeddedPPObj.closeFlow();
// More UI code here...
};
}
var myEmbeddedPaymentFlow = new MyEmbeddedFlow(dgFlow);
</script>
The server code
# Make a Pay request to PayPal API.
paypal_payment_thread = Thread.new do
# Some preparation code goes here...
pay_request = PaypalAdaptive::Request.new
process_guid = SecureRandom.uuid
# Construct Pay API request data.
data = {
:returnUrl => "#{PAYPAL_RETURN_URL}?process_guid=#{process_guid}",
:cancelUrl => "#{PAYPAL_CANCEL_URL}?process_guid=#{process_guid}",
:requestEnvelope => {
:errorLanguage => "en_US"
},
:currencyCode => "USD",
:receiverList => {
:receiver => [{
# seller_paypal value is different for two payments.
# But in fact we do the last payment for both payments.
:email => seller_paypal,
:amount => ORDER_SELLER_AMOUNT,
:paymentType => "DIGITALGOODS"
}, {
:email => PAYPAL_MARKETPLACE_EMAIL,
:amount => ORDER_MARKETPLACE_AMOUNT,
:paymentType => "DIGITALGOODS"
}]
},
:actionType => "PAY",
:ipnNotificationUrl => PAYPAL_NOTIFY_URL,
:reverseAllParallelPaymentsOnError => "true",
:trackingId => process_guid
}
# Make a Pay API request.
pay_response = pay_request.pay(data)
if pay_response.success?
# Everything is ok. Update database here...
else
raise Exceptions::PaypalPaymentError
end
end
I've removed some unimportant code just to be clear, how it really works.
Thanks in advance for the help!
Looks like it is by design. I've tried the same test here on the website of one of PayPal's employees and it is reproducible there.
PayPal's support answered me that the problem in using Lightbox. However I've tried Mini-Browser and Popup options as I described in my post without no effect.
Also, PayPal's support answered me that this is by design and adviced me to contact with Technical Support. Maybe it will be useful for someone else.
Hi Michael, Thanks, yes I was able to reproduce it as well. However
it’s important to understand that PayPal is not made for handling 2
payment flows at the same time. If you want to get further on that,
you can contact our Technical Support : https://ppmts.custhelp.com/
They have other tools to debug and may be able to give you a better
understanding of the technical problem.
Finally I've blocked simultaneous payments using a special flag in HTML5 Local Storage and dgFlow.isOpen() method of PAYPAL.apps.DGFlow object to detect PayPal window. On window close I reset this flag using onunload and onbeforeunload events of window.
I close this question. Thanks.
I'm developing an affiliate script with the Paypal Adaptive Payments SDK. I have the following code:
$payRequest = new PayRequest(new RequestEnvelope("en_US"), 'PAY',$arrPaypal ['paypal_return'] , 'USD', $receiverList, $arrPaypal['paypal_return']);
$payRequest->IpnNotificationUrl = $arrPaypal['paypal_callback'];
$payRequest->memo = 'Payment for ' . $arrUserInfo['plan_title'];
$payRequest->trackingId = $intID;
However it is not firing the callback script. The url is my http:// ipaddress /script.php. If I set it in the paypal sandbox I get a hit but it's not an adaptive payments response as detailed in the sdk. Could someone please explain how to enable it?
You may have gotten the case of the IPN setter wrong. Try ipnNotificationUrl instead of IpnNotificationUrl
I'm trying to get PayPal's chained payments working in their sandbox env. but whenever I click on "Pay" at the very last stage after signing in I always get redirected to a page with the generic error message "Your payment can't be completed. Please return to the participating website and try again."
I've tried doing both chained and parallel payments with the same results.
I've also followed a few suggestions from around the web which inc tweaking the merchant account settings making sure certain fields were unchecked under the "blocked" options. As well checking currency and country code. Initially country code was en_GB and currency GBP, that didn't work I tried doing en_US with USD but in all cases I get the same message.
I've also tried adding an IPN url on the off chance PayPal would post some error code/message to it but got nadda! If you click "Return to test store" it goes to the cancel URL without any POST/GET parameters.
I'm using their PHP SDK from http://paypal.github.io/#adaptive-payments-tab-php-5-3
So the question, does anyone have any suggestion as to how I can find out what exactly is going wrong or other things I can try to fix it?
I had this problem in the sandbox environment because I was not including an application ID. I used APP-80W284485P519543T which one of examples indicated as the Sandbox Application ID, and then it worked.
Mobile Payments Library Developer Guide and Reference
–
Android OS
Edition
Oct 2016
5
Preface
**Important:
The Mobile Payments Library is based on the PayPal Adaptive Payments API.
As of October 6, 2016, Adaptive Payments is now a limited releas
e product. It is restricted to
select partners for approved use cases and should not be used for new integrations without guidance from PayPal**
=============================================
first implement method
private void initLibrary() {
PayPal pp = PayPal.getInstance();
if(pp == null) {
pp = PayPal.initWithAppID(this, PAYPAL_APP_ID, PayPal.ENV_SANDBOX);
pp.setLanguage("en_US"); // Sets the language for the library.
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// pp.setShippingEnabled(true);
pp.setDynamicAmountCalculationEnabled(false);
}
}
**paypal button click event code**
double secondary_payment = 0;
double primary_payment = 0;
PayPalAdvancedPayment advPayment = makeChainedPayment(secondary_payment,primary_payment,"primary_email","secondary_email");
Intent checkoutIntent = PayPal.getInstance().checkout(advPayment, your_current_activity);
startActivityForResult(checkoutIntent, 1);
=============================================
private PayPalAdvancedPayment makeChainedPayment(double priceSecondary, double pricePrimary, String primary_email, String secondary_email) {
PayPalAdvancedPayment payment = new PayPalAdvancedPayment();
payment.setCurrencyType("USD");
// payment.setMerchantName("PushND");
BigDecimal bigDecimalPrimary=new BigDecimal(pricePrimary);
PayPalReceiverDetails receiverPrimary = new PayPalReceiverDetails();
receiverPrimary.setRecipient(primary_email);
//receiverPrimary.setRecipient("adaptive_receiver_1#pushnd.com");
receiverPrimary.setSubtotal(bigDecimalPrimary);
receiverPrimary.setIsPrimary(true);
payment.getReceivers().add(receiverPrimary);
PayPalReceiverDetails receiverSecondary= new PayPalReceiverDetails();
receiverSecondary.setRecipient(secondary_email);
BigDecimal bigDecimalSecond=new BigDecimal(priceSecondary);
receiverSecondary.setSubtotal(bigDecimalSecond);
payment.getReceivers().add(receiverSecondary);
return payment;
}
We are looking to replace our usage of Authorize.net. I've spent a good deal of time looking into the PayPal documentation but can't find a clear answer to my question:
Using the thousands tens of different PayPal APIs is it possible to have a checkout process that is hosted on our site, where we capture and process the credit card information from the customer without the customer ever leaving our site and without the customer ever having to see anything PayPal related (so PayPal is 100% invisible).
I'm confused by this PayPal documentation page:
"Please note: Direct Payment API is not a stand-alone product. You are required to use Direct Payment API and Express Checkout together as part of the Website Payments Pro solution." as Express Checkout requires you to show PayPal logos, etc.
And this page makes it pretty clear that you have to offer the branded Express checkout option to use the Direct Payments API.
I guess I'm just looking for confirmation that there are people on SO that use PayPal in this way and have not had problems keeping PayPal 100% invisible to the customer?
Yes you can.. We use PayPal on our website,PerqWorks and only allow payment by credit card. The PayPal product is Website Payments Pro. I did the integration, it was fairly easy, and the cost is low if your sales are under $10K a month..
EDIT:: I need to clarify this -- we received an exception from PayPal to allow us to not have the PayPal button on our site. I missed this information because someone else in my office actually made this arrangement. My advice is that you ask your PayPal Integration Account person, that is who made the exception for us..
The only way I know of to fully integrate and take the PayPal branding out of the process is to use their Payflow Pro gateway service. I've used it before and it's pretty similar to dealing with any other payment gateway (such as Authorize.net).
However, this is entirely up to you but I've found that there are still some people who prefer to use their PayPal account. They might be afraid of the potential lack of security on small-ish or unknown e-commerce sites. Or perhaps they're ordering from another country, in which case a PayPal account offers abundant funding options and automatic currency conversion. So it's nice to at least offer the option of a PayPal Standard Checkout process, or something similar.
I can't give you a definite no, but I'm fairly certain PayPal wouldn't allow it. They depend on revenue that comes from using a buyer's PayPal balance or bank account to pay for something and charging the merchant a percentage. The merchant's percentage doesn't do much more than cover the credit card issuer's charge.
Short of entering the users PayPal credentials on your site, it wouldn't be possible for them to use a funding source other than credit cards. The issue with that is that it would create a huge vulnerability to phishing attacks to have users become accustomed to entering their PayPal login information on a non-PayPal site.
You're basically talking about a standard credit card merchant account at that point.
You can definitely use Paypal as a stand alone credit card processing. The paypal account has to be set up for paypal pro.
You can download the API DLLs from the paypal dev site.
paypal_base.dll
log4net.dll
Here is an example function on how to use it for VB.NET but you can convert to C# relatively easily:
Imports com.paypal.sdk.services
Imports com.paypal.soap.api
Imports com.paypal.sdk.profiles
Private Function processCC() As Boolean
Dim caller As New CallerServices
Dim profile As IAPIProfile = ProfileFactory.createSignatureAPIProfile
profile.APIUsername = AppSettings("APIUsername")
profile.APIPassword = AppSettings("APIPassword")
profile.APISignature = AppSettings("APISignature")
profile.Environment = AppSettings("Environment")
caller.APIProfile = profile
Dim pp_Request As New DoDirectPaymentRequestType
pp_Request.Version = "51.0"
pp_Request.DoDirectPaymentRequestDetails = New DoDirectPaymentRequestDetailsType
pp_Request.DoDirectPaymentRequestDetails.IPAddress = Request.ServerVariables("REMOTE_ADDR")
pp_Request.DoDirectPaymentRequestDetails.MerchantSessionId = Session.SessionID
pp_Request.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale
pp_Request.DoDirectPaymentRequestDetails.CreditCard = New CreditCardDetailsType
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = Request("ccNumber")
Select Case Request("ccType")
Case "visa"
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa
Case "mastercard"
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard
Case "amex"
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Amex
Case "discover"
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Discover
End Select
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CVV2 = Request("CVV2")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = Request("expMonth")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonthSpecified = True
pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYear = Request("expYear")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYearSpecified = True
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner = New PayerInfoType
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Payer = Request("email")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerID = ""
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerStatus = PayPalUserStatusCodeType.unverified
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerCountry = CountryCodeType.US
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = New AddressType()
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = Request("address1")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = Request("address2")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = Request("city")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = Request("state")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = Request("zipcode")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountryName = "USA"
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = True
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = New PersonNameType()
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = Request("firstname")
pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = Request("lastname")
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails = New PaymentDetailsType()
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = New BasicAmountType()
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD
Dim myOrder As Order = CType(Session("currentOrder"), Order)
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = FormatNumber(myOrder.grandTotal, 2)
'pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal = New BasicAmountType()
'pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.currencyID = CurrencyCodeType.USD
'pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.Value = FormatNumber(myOrder.orderShippingTotal, 2)
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal = New BasicAmountType()
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.currencyID = CurrencyCodeType.USD
pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.Value = FormatNumber(myOrder.orderSubTotal, 2)
'// Execute the API operation and obtain the response.
Dim pp_response As New DoDirectPaymentResponseType()
pp_response = CType(caller.Call("DoDirectPayment", pp_Request), DoDirectPaymentResponseType)
Session("myResponse") = pp_response
Dim rtn As Boolean = False
Select Case pp_response.Ack
Case AckCodeType.Failure
rtn = False
Case AckCodeType.FailureWithWarning
rtn = False
Case AckCodeType.Success
Return True
Case AckCodeType.SuccessWithWarning
rtn = True
Case AckCodeType.Warning
rtn = False
End Select
Return rtn
End Function
At one time I used Paypal Pro for this very purpose. In looking at your link, it does seem they require you to use both paypal checkout and regular checkout.
However, you can still achieve your purpose. What happens is that they can checkout and not know anything about it going through paypal OR they can click the paypal button and leave your web site. After payment, you can set up the 'thank you' return page back to your site.
Other than that, you'd have to get them to approve an exception.
I can't tell you about the API of Paypal, but I have something burning inside me, reading your topic.
For me as a user it is highly ugly to just see a form of a random site that claims for my payment data. Having a hint on where my data is actually going is by far more better, but really positive it is only, if the site sends me to paypal, where I can let my payment data, inform me about paypal, verify that I'm sending my data to paypal, etc.
It a sort of security you take from your customers if you do it all behind the scenes - even if you write to them, that their payment data is only handled by paypal, there's no transparent way for them to check that.
I'd take the chance to make a poll under your customers for that, what they would prefer, before implementing something obscure.