PHP code example of leifermendez / laravel-paypal-subscription
1. Go to this page and download the library: Download leifermendez/laravel-paypal-subscription library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
leifermendez / laravel-paypal-subscription example snippets
'providers' => array(
//...
leifermendez\paypal\ProviderPaypalSubscription
),
'aliases' => array(
//...
'PapyalSubscription' => leifermendez\paypal\PaypalSubscriptionFacade,
),
$product = [
'name' => 'iPhone X',
'description' => 'Awesome item, phone, etc',
'type' => 'SERVICE',
'category' => 'SOFTWARE',
'image_url' => 'https://avatars.githubusercontent.com/u/15802366?s=460&u=ac6cc646599f2ed6c4699a74b15192a29177f85a&v=4',
'home_url' => 'https://github.com/leifermendez/laravel-paypal-subscription',
];
$response = PapyalSubscription::createProduct($product);
dd($response);
$response = PapyalSubscription::getProduct();
dd($response);
$plan = [
'name' => 'Video Streaming Service Plan',
'description' => 'Video Streaming Service basic plan',
'status' => 'ACTIVE',
'billing_cycles' => [
[
'frequency' => [
'interval_unit' => 'MONTH',
'interval_count' => '1'
],
'tenure_type' => 'REGULAR',
'sequence' => '1',
'total_cycles' => '12',
'pricing_scheme' => [
'fixed_price' => [
'value' => '3',
'currency_code' => 'USD'
]
]
]
],
'payment_preferences' => [
'auto_bill_outstanding' => 'true',
'setup_fee' => [
'value' => '10',
'currency_code' => 'USD'
],
'setup_fee_failure_action' => 'CONTINUE',
'payment_failure_threshold' => '3'
],
'taxes' => [
'percentage' => '10',
'inclusive' => false
]
];
$product = [
'product_id' => 'PROD-5C186753RC8244822' //<--------***** ID DEL PRODUCTO
];
$response = PapyalSubscription::createPlan($plan, $product);
dd($response);
$response = PapyalSubscription::getPlans();
dd($response);
$subscription = [
'start_time' => '2022-11-01T00:00:00Z',
'quantity' => '1',
'shipping_amount' => [
'currency_code' => 'USD',
'value' => '10'
],
'subscriber' => [
'name' => [
'given_name' => 'Leifer',
'surname' => 'Mendez'
],
'email_address' => '[email protected]',
'shipping_address' => [
'name' => [
'full_name' => 'Joe'
],
'address' => [
'address_line_1' => '2211 N First Street',
'address_line_2' => 'Building 17',
'admin_area_2' => 'San Jose',
'admin_area_1' => 'CA',
'postal_code' => '95131',
'country_code' => 'US'
]
]
],
'application_context' => [
'brand_name' => 'Racks',
'locale' => 'es-ES',
'shipping_preference' => 'SET_PROVIDED_ADDRESS',
'user_action' => 'SUBSCRIBE_NOW',
'payment_method' => [
'payer_selected' => 'PAYPAL',
'payee_preferred' => 'IMMEDIATE_PAYMENT_REQUIRED',
],
'return_url' => 'https://github.com/leifermendez?status=returnSuccess',
'cancel_url' => 'https://github.com/leifermendez?status=cancelUrl'
]
];
$plan = [
'plan_id' => 'P-6LP13543ED649531TMAWPBHA' // <-------- ************ ID DEL PLAN CREADO
];
$response = PapyalSubscription::createSubscription($subscription, $plan);
$id_subscription = 'I-25E9NV7WG2G3'; // <----- ********* ID SUBSCRIPCION
$response = PapyalSubscription::getSubscription($id_subscription);
dd($response);
$id_subscription = 'I-25E9NV7WG2G3'; // <----- ********* ID SUBSCRIPCION
$response = PapyalSubscription::suspendSubscription($id_subscription);
dd($response);
$id_subscription = 'I-25E9NV7WG2G3'; // <----- ********* ID SUBSCRIPCION
$response = PapyalSubscription::cancelSubscription($id_subscription);
dd($response);