I create a product, with product id a plan, and with a plan a subscription, but I don't know where should I add the merchant id or email.
Here is the code, how I create a subscription now:
//create product
$http = Http::withHeaders([
'Authorization' => 'Basic '.$headerForBasicAuth,
'Content-Type' => 'application/json'
]);
$body = [
'name' => "example sub",
'type' => "DIGITAL",
];
$response = $http->post($this->paypalModel->getBasePath().'/v1/catalogs/products', $body)->body();
$product = json_decode($response);
if($data['price']==1){
$subPrice = $subscription->monthly_fee;
$interval = "MONTH";
}else{
$subPrice = $subscription->annual_fee;
$interval = "YEAR";
}
//create plan
$body = [
'billing_cycles' => [
[
'frequency' => [
"interval_unit" => $interval,
"interval_count" => 1
],
"tenure_type" => "REGULAR",
"sequence" => 1,
"total_cycles" => 0,
"pricing_scheme" => [
"fixed_price" => [
"value" => $subPrice,
"currency_code" => "USD",
]
]
],
],
'name' => "example plan",
'payment_preferences' => [
"auto_bill_outstanding" => true,
"payment_failure_threshold" => 0
],
'product_id' => $product->id,
];
$response = $http->post($this->paypalModel->getBasePath().'/v1/billing/plans', $body)->body();
$plan = json_decode($response);
//create subscription
$body = [
'plan_id' => $plan->id,
'application_context' => [
'cancel_url' => 'http://laravel-paypal-example.test',
'return_url' => 'http://laravel-paypal-example.test',
'shipping_preference' => 'NO_SHIPPING',
]
];
$response = $http->post($this->paypalModel->getBasePath().'/v1/billing/subscriptions', $body)->body();
$sub = json_decode($response);
I want to add somewhere the merchant id, and the sum or the percentage of amount, but I don't know where should I do this.
You can't. PayPal Subscriptions will send money to the merchant's account, and the most straightforward way to integrate them for a merchant is with that merchant's client ID and secret. The plans must also be created in the merchant's account. The full payment amount will go to the merchant's account.
To set up / some type of process for recurring payment, where money is paid directly to a merchant's account plus and some fee goes to you, as PayPal Subscriptions is not suited to that you'll need a combination of:
partner_fee
when onboarding new merchants.To be approved for (1) and to be approved for (2), contact PayPal. You won't be able to complete this type of integration without its approval and support.