October 22, 2024
Chicago 12, Melborne City, USA
PHP

srmklive/paypal AUTHORIZE Order with platform_fee in 2024


I need to setup paypal orders for a upcoming marketplace website (buyers, merchants and me the platform), but i fail to implement the platform_fee. Internet searches lead me to some paypal marketplace api that I cannot find in my sandbox dev account. The payment goes from buyer to merchant without deducting the platform_fee.

I read a lot online but most of the linked urls are broken in the paypal docs and i dont know whats the way in 2024 now. Some people say the sandbox account should be enough already, while other people say i need to be in a paypal partner program while other people say i would need to use a marketplace api and i even read somehwere that its not possible with AUTHORIZE orders, im very confused.

Here is my workflow right now

Buy Article (create order)

$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypalToken = $provider->getAccessToken();

$orderData = $provider->createOrder([
    "intent" => "AUTHORIZE",
    "purchase_units" => [
        [
            "amount" => [
                "currency_code" => "EUR",
                "value" => $article->price,
            ],
            "payee" => [
                "email_address" => $sellerPayPalEmail
            ] 
        ]
    ],
    "application_context" => [
        "return_url" => route('article.purchase.success', ['id' => $article->id]) . '?status=success',
        "cancel_url" => route('article.purchase.cancel', ['id' => $article->id]) . '?status=cancel',
    ]
]);

article.purchase.success (authorizePaymentOrder)

$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypal = $provider->getAccessToken();
$provider->setAccessToken($paypal);

$payerId = $request->query('PayerID');
$token = $request->query('token');

$response = $provider->showOrderDetails($token);

$authorizationResponse = $provider->authorizePaymentOrder($response['id']);
authorizePaymentOrder()

CaptureAuthorizedPayment (if i want to process the transaction)

$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypalToken = $provider->getAccessToken();

$captureResponse = $provider->captureAuthorizedPayment(
    $authorizationId,
    'INVOICE-' . uniqid(),
    $articlePrice,
    'Payment for article',
    [
        'platform_fees' => [
            [
                'amount' => [
                    'currency_code' => 'CHF',
                    'value' => 15 
                ],
                'payee' => [
                    'email_address' => $platformPayPalEmail
                ]
            ]
        ]
    ]
);



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video