PayPal Sandbox 400 error after redirection - laravel

i use laravel V6
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'token..',
'token..'
)
);
//dd($transaction);
$callbackUrl = url('/paypal/status');
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl($callbackUrl)
->setCancelUrl($callbackUrl);
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
try {
$payment->create($apiContext);
//dd($payment);
//dd($payment->getApprovalLink());
return redirect()->away($payment->getApprovalLink());
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
var_dump(json_decode($ex->getData()));
exit(1);
}
that's the controller, I followed the documentation enter link description here
but I get a 400 error enter link description here
The link it generates is as follows https://www.sandbox.paypal.com/webapps/hermes?flow=1-P&ulReturn=true&token=EC-88M93704JL735000S&country.x=US&locale.x=es_XC#/checkout/genericError?code=UEFZTUVOVF9ERU5JRUQ%3D
I can not understand why the error .. the client_id secret, are fine .. anyway it is directly in the controller and check that the sandbox account has a balance

For that ClientId/Secret it looks like the receiving account in the PayPal sandbox is from a country that cannot receive any payments, such as Bolivia. Create a new sandbox business account at https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts%2F for a different country that is able to receive PayPal payments, and then create a REST app for this new sandbox business account in the 'My Applications' side tab.
It looks like you are using an obsolete PHP integration, with the old v1 payments SDK
You should instead use the v2 Checkout-PHP-SDK, with two routes, one for 'Set Up Transaction' and one for 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
Instead of redirecting to the approval URL, use this front-end UI: https://developer.paypal.com/demo/checkout/#/pattern/server -- this gives an "in context" checkout experience that keeps your site loaded in the background, which provides a much superior modern web experience

Related

How to get payer email after a success payment wit paypal API (Laravel paypal/rest-api-sdk-php)?

I'm using the paypal API with Laravel, everything works fine. I just need to find the way to get the user email address and name.
$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId( $request->query('PayerID') );
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {
// I should get the info about the payer here
}
The v1/payments PayPal-PHP-SDK is deprecated, you should not use it for any new integration.
The current supported SDK is the v2/checkout/orders Checkout-PHP-SDK, which you should use instead.
You can try the srmklive package "v3" if you like, otherwise integrate directly.
You should be able to create two routes, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
The capture order response may have details about the payer and payment, if not use can do a 'Get' API call on the order ID for this information. Store it in your database before returning the JSON to the client code.

Laravel redirect() method not working with Android google chrome

I am a backend developer having redirection issue with Android google chrome.
The website i developed is integrated with a payment gateway.
The process for payment is as follow:-
1- Payment order created on website DB.
2- API request sent to payment gateway for creating a payment request.
3- API gateway response with providing a payment URL.
4- User been redirected to that payment URL.
5- Once user successfully paid and payment status get captured, the payment gateway website redirect user back to my website through the following link:-
http://mywebsite.com/payment/callback?cancelled=0&hash=5e02f05b78766&order_id=277&tx_date=31-December-2019%2008:16:03&tx_amt=4.1000&Result=CAPTURED&PaymentID=106201936565342280&PostDate=1231&TranID=201936565319193&Auth=259819&Ref=936533003451&tx_id=386306&tx_mode=KNET&tx_status=
6- In backend code Controller that process the route (/payment/callback) i have the following php code:-
public function callback(Request $request)
{
// Check if cancelled value = 1 (user cancelled) OR cancelled in knet payment page
if ($request->cancelled OR (!$request->cancelled && $request->Result == 'CANCELED') OR $request->Result != 'CAPTURED')
{
//Here to return to view if the payment is cancelled in gateway payment page
echo 'the request cancelled';
return redirect()->route('payment_status')->with($request->all());
}
//Query order
$order = Order::where('payment_ref',$request->hash)->first();
\Auth::login($order->user);
if ($order == null) {
return 'Could Not Find Order, Please Contact IT Support';
}
if (!$request->cancelled && $request->Result = 'CAPTURED')
{
if ($order->status === 'closed'){
die('This Page Has Been Expired');
}
$order->status = 'closed';
$order->save();
return redirect()->route('payment_status')->with($request->all());
}
The issue is when user using a google chrome (Android version) is show him a message :-
This Page Has Been Expired
While it suppose to show him the transaction details, as been made from the following code (other browsing is working fine):-
return redirect()->route('payment_status')->with($request->all());
I tried with the following google chrome mobile phone (Samsung Note 9 and OnePlus 3T).
*The php framework used (Laravel).
Please advice.
I believe the first problem is:
if (!$request->cancelled && $request->Result = 'CAPTURED')
you assign here CAPTURED to result and it should be probably
if (!$request->cancelled && $request->Result == 'CAPTURED')

How to implement Paypal checkout option in Xamarin.Forms?

I am make an M-Commerce application with the use of Xamarin.Forms in that user is able to checkout with payment integration and I have to use paypal method for checkout option and I am using .NET Standard project and project is also refer to the UWP. I check default paypal with example but I am not getting help.
I have new in payment integration method.
Can anyone look into this and suggest me what should I have to do in that?
You can use the Paypal Forms plugin for this:
In MainActivity(Android)/AppDelegate(iOS) after "Forms.Init()" call the Init method with your PayPal config value
global::Xamarin.Forms.Forms.Init ();
var config = new PayPalConfiguration(PayPalEnvironment.NoNetwork,"Your PayPal ID from
https://developer.paypal.com/developer/applications/")
{
//If you want to accept credit cards
AcceptCreditCards = true,
//Your business name
MerchantName = "Test Store",
//Your privacy policy Url
MerchantPrivacyPolicyUri = "https://www.example.com/privacy",
//Your user agreement Url
MerchantUserAgreementUri = "https://www.example.com/legal",
// OPTIONAL - ShippingAddressOption (Both, None, PayPal, Provided)
ShippingAddressOption = ShippingAddressOption.Both,
// OPTIONAL - Language: Default languege for PayPal Plug-In
Language = "es",
// OPTIONAL - PhoneCountryCode: Default phone country code for PayPal Plug-In
PhoneCountryCode = "52",
};
//iOS
CrossPayPalManager.Init(config);
//Android
CrossPayPalManager.Init(config, this);
...
You can find all the important API's on their Github itself.
In case of issues or anything of that sort feel free to revert

Using New Google API Console project getting unauthorized_client ,Client is unauthorized to retrieve access tokens using this method

I created a Google API Console project and client ID with web application type.Then Using OAuth 2.0 Playground - Google Developers I authorized to drive, sheet and calendar scopes using my client id.
Also, Service account client id and scopes added and authorized in G Suite.
I tried to list files in a folder in the drive using the below sample
index.php
<?php
require_once 'vendor/autoload.php';
require_once 'vendor/google/apiclient/examples/templates/base.php';
$service = get_service_document();
$folderid='FOLDER_ID';
try {
$children1 = $service->files->listFiles(array(
'q' => "'$folderid' in parents "));
$filearray1 = $children1;
}
catch(Exception $e){
echo $e->getMessage();
}
print_r($children1);
exit;
function buildServiceDrive($userEmail,$service_id,$scope,$service_filename) {
$client = new Google_Client();
putenv("GOOGLE_APPLICATION_CREDENTIALS=".$service_filename);
if ($credentials_file = checkServiceAccountCredentialsFile()) {
// set the location manually
$client->setAuthConfig($credentials_file);
}
elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
// use the application default credentials
$client->useApplicationDefaultCredentials();
}
else {
echo missingServiceAccountDetailsWarning();
return;
}
$client->setApplicationName("DRIVE");
$client->setScopes('https://www.googleapis.com/auth/drive');
$client->setSubject($userEmail);
return new Google_Service_Drive($client);
}
//COMMON FUNCTION TO CREATE CALENDAR ID
function get_service_document(){
$userstamp='user#domain.com';
$driveService =buildServiceDrive($userstamp,'','','project-id-451a5f6b12ce.json';
return $driveService;
}
But I got this issue
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}
I m getting this issues newly created Google API Console project only
Please help me to solve this.
Thanks in advance
This is a common error when running an API call with a service account but not properly completing the domain-wide delegation (DWD) or because the authorization in the admin console has not propagated yet.
This article explains in details the process of DWD. If you have done that, wait 24 hours and it should work. If it doesn't work after that, then it must be something else but as far as I can say right now, the DWD process is the issue.
PLEASE NOTE: DWD is available only to G Suite customers. If you are using a consumer gmail.com account, you won't be able to do this. Instead, you'll have to go through the user consent OAuth flow.
This error could also occur if API client only have write permissions and in scope you specify that you only need readonly access.
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}

Connecting to Magento API with SOAP

I'm trying to follow a tutorail on connecting to magento API with Soap, but am stuck already ? SOAP seems to be installed on my sever as i can browse to the ?wsld and it displays an xml file.
I've setup the user and role in magento admin webservices.
i'm confused by 2 things in the tutorial
choosing a soap client, In this tutorial we will assume the usage of the PHP SoapClient. what is this where do i find it ?
Logging with the SOAP client
"So let's create a simple PHP-script that allows us to login into Magento through SOAP. The logic is here that we first need to initialize a new SoapClient object with as argument the Magento SOAP URL."
// Magento login information
$mage_url = 'http://MAGENTO/api/?wsdl';
$mage_user = 'soap_user';
$mage_api_key = '********';
// Initialize the SOAP client
$soap = new SoapClient( $mage_url );
// Login to Magento
$session_id = $soap->login( $mage_user, $mage_api_key );
Where do you create this script - is it a simple php file ? and how do you actualy make the call - do you just browse to it ?
http://blog.opensourcenetwork.eu/tutorials/guru/connecting-through-soap-with-magento-1
Many thanks in advance
You put this into a new blank file. Save this as name.php und run this is on your server:
<?php
$host = "127.0.0.1/magento/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
$apiuser= "user"; //webservice user login
$apikey = "key"; //webservice user pass
$action = "sales_order.list"; //an action to call later (loading Sales Order List)
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
print_r($client->call($sess_id, $action));
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
Regards boti
Yes, the Soap Client the documents refer to is the built in PHP SoapClient object. There are a plethora of soap client's written in a plethora of different languages. SOAP, as a protocol, is language/platform independent. (although individual languages/platforms tend to have their own quirks). Magento provides a Soap Server, which can interacted with via a client. This is client/server architecture.
You call this script however you want. You can load it in an individual web page, you can run it from the command line $ php script.php, you can put it in an include files, you can place it in another framework's class files, etc.
this helped alot thanks
answered Nov 16 '11 at 7:26 boti
You put this into a new blank file. Save this as name.php und run this is on your server:
<?php
$host = "127.0.0.1/magento/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
$apiuser= "user"; //webservice user login
$apikey = "key"; //webservice user pass
$action = "sales_order.list"; //an action to call later (loading Sales Order List)
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
print_r($client->call($sess_id, $action));
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
HI All,
The solution is :
from Magento Admin Panel...
System -> Configuration -> Web -> Url Options -> Add Store Code to Urls = NO
AND !!!!
Auto-redirect to Base URL = NO
Then Add user from
System -> Web Services-> Users
Make a user to use with the soapclient
Then make a role from
System -> Web Services -> Roles
Attach all resources if you want do it this way.
This is important ! add this role to the user you’ve just created
Also Make sure that PHP.ini from
;extension=php_soap.dll
to
extension=php_soap.dll
Then you can connect with this user I use this code
$proxy = new SoapClient(’http://localhost/api/soap/?wsdl’,array(
$apiuser = "user",
$apikey = "key"));
download soapui from forgesource
http://sourceforge.net/projects/soapui/?source=directory
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<username xsi:type="xsd:string">username</username>
<apiKey xsi:type="xsd:string">password</apiKey>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
Get the link of our server with link below and save as magentoV2.wsdl
http://localhost/index.php/api/v2_soap?wsdl
I hope this will help others because I a lost half a day to understand this simple things because there were no enough detail information on one place.
HR
They are referring to the standard SOAP client functionality of PHP(provided, i can't read the link you posted, but I'm assuming it is). Have a look here for more: http://php.net/manual/en/class.soapclient.php
As per your question i will tel you simple steps, follow those steps then you wii get result as we require.
1. Login to Magento admin panel then navigate to system-->webservices-->SOAP RPC Roles create SOAP RPC roles
2. Navigate to system-->webservices-->SOAP RPC users create SOAP RPC user map this user with roles.
3. Create one PHP file name it as magentoapi.php inside xampp-->htdocs-->folder(project name).
4. Here I am giving you one example, how to get customer Info.
5. Open magentoapi.php file create one function name it as customerInfo
Below is the code:
function customerInfo($api_url, $api_user, $api_pwd) {
$websites = '' . $api_url . "/index.php/api/soap/?wsdl";
try {
$client = new SoapClient($websites);
$session = $client->login($api_user, $api_pwd);
$result = $client->call($session, 'customer.info', '1');
print_r($result);
} catch (\SoapFault $e) {
echo $e->getMessage();
}
}
Here,
$api_url is your store url,$api_user= api user name, $api_pwd = api password
pass this value to the customerInfo function. We will get complete information about a particular customer
Do same thing for all functions
Here is the API reference URL http://devdocs.magento.com/guides/m1x/api/soap/customer/customer.list.html
Finally run the below URL in browser you will get results
http://localhost/yourprojectname/magentoapi.php?functionName=customerLogout&store_url=http://127.0.0.1/magento19&api_username=magento&api_key=123456

Resources