How can I make a subscription, where the half of the amount go to merchant?
Jozsef123
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Dec-17-2022
10:41 AM
I make 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 make 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' => [
'shipping_preference' => 'NO_SHIPPING',
]
];
$response = $http->post($this->paypalModel->getBasePath().'/v1/billing/subscriptions', $body)->body();
$sub = json_decode($response);
return response()->json(['sub_id' => $sub->id]);
Labels:
- Labels:
-
Payments REST APIs
-
Subscriptions
0 REPLIES 0

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- How to enable on-demand / recurring payments to existing PayPal checkout? in SDKs
- Webhook event is not firing if the cancellation is initiated by the merchant in REST APIs
- Subscription did not get auto renewed in sandbox mode but it was created successfully in Sandbox Environment
- AUTHORIZED Orders with platform_fee 2024 in REST APIs
- How to Enable or Disable Subscription Auto-Renewal? in REST APIs