How can I make a subscription, where the half of the amount go to merchant?

Jozsef123
Contributor
Contributor

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' => [
                '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);
        return response()->json(['sub_id' => $sub->id]);
Login to Me Too
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.