i know, the paypal documentation is very confusing and badly written, even the sdk has duplicate class names that clashes on the composer autoloader.
what have you done so far?
i have just install it but not able to understand from where to start..
Hi,
I kown it's late but this could be somehow useful. It could be a good starting point.
So, first update your composer.json with :
"require": {
...
"paypal/adaptivepayments-sdk-php": "v3.6.106"
},
Then you need to create credentials for your Sandbox, go to developer.paypal.com.
I'm not sure where to create the AppId :
Basically you can try something like this :
<?php
namespace App\Http\Controllers;
use PayPal\Core\PPHttpConfig;
use PayPal\Service\AdaptivePaymentsService;
use PayPal\Types\AP\PayRequest;
use PayPal\Types\AP\Receiver;
use PayPal\Types\AP\ReceiverList;
class PaypalController extends SubscriptionsController
{
/**
*
*/
public function config()
{
// Credentials
// https://developer.paypal.com/developer/accounts/
// AppId
// https://www.paypal-apps.com/user/my-account/applications/manage#most_recent
return [
'mode' => 'sandbox',
'acct1.AppId' => 'APP-80W284485P519543T',
'acct1.UserName' => 'account-facilitator_api1.yoursite.com',
'acct1.Password' => '1234567890',
'acct1.Signature' => 'AqtM9B4LqfjmFaY2aqlxRZ6dcqdcdqcdqcrzgerg1GsLLrUOlDyrxwjo',
];
}
/**
* Redirect to Paypal.
*/
public function redirect($payKey = '')
{
$url = redirect('https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey='.$payKey);
return $url;
}
/**
* Ask Paypal for a token
*/
public function showCheckout()
{
$requestEnvelope = ['errorLanguage' => 'fr_FR'];
$actionType = 'PAY';
$cancelUrl = 'http://.../url-payment-cancel';
$returnUrl = 'http://.../url-payment-success';
$currencyCode = 'EUR';
// Your request
$_POST['receiverEmail'] = ['[email protected]'];
$_POST['receiverAmount'] = ['3.00'];
$receiver = [];
for ($i = 0; $i < count($_POST['receiverEmail']); ++$i) {
// Parallel Payments
$receiver[$i] = new Receiver();
$receiver[$i]->email = $_POST['receiverEmail'][$i];
$receiver[$i]->amount = $_POST['receiverAmount'][$i];
}
$receiverList = new ReceiverList($receiver);
$payRequest = new PayRequest($requestEnvelope, $actionType, $cancelUrl,
$currencyCode, $receiverList, $returnUrl);
// Set the correct the value 1, 3, 4, ...
// PPHttpConfig::$DEFAULT_CURL_OPTS[CURLOPT_SSLVERSION] = 4;
$config = $this->config();
$service = new AdaptivePaymentsService($config);
$response = $service->Pay($payRequest);
if (strtoupper($response->responseEnvelope->ack) == 'FAILURE') {
dd($response->error);
}
if (strtoupper($response->responseEnvelope->ack) == 'SUCCESS') {
return $this->redirect($response->payKey);
}
return view('payment.checkout');
}
}
For the moment, I'm stuck there. ipnNotificationUrl is nerver called. I'm not sure that is possible to have more than one ipnNotificationUrl by Paypal account. Maybe you can use WEBHOOKS in the App definition https://developer.paypal.com/developer/applications/
If you try https://developer.paypal.com/developer/ipnSimulator/ remember to use https, set your route with post and finally add your route to app/Http/Middleware/VerifyCsrfToken.php to avoid token mismatch.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community