leifermendez / laravel-paypal-subscription
特别为 Laravel 设计的插件,可以轻松实现通过 PAYPAL 收取订阅费用
v1.0.4
2021-02-18 16:27 UTC
Requires
- php: >=7.2
- anlutro/curl: ^1.4
README
以周期性和自动化的方式在 PayPal 上进行收费,使用 PayPal 订阅。
注意:在继续之前,请记得在 PAYPAL 上申请访问凭证
安装
composer require leifermendez/laravel-paypal-subscription
Laravel 5.4 或更低版本
将服务提供者添加到您的 config/app.php
文件中
'providers' => array( //... leifermendez\paypal\ProviderPaypalSubscription ),
将外观添加到您的 config/app.php
文件中
'aliases' => array( //... 'PapyalSubscription' => leifermendez\paypal\PaypalSubscriptionFacade, ),
使用方法
请记住将凭证放入您的 .env 文件中,模式:"test" 或 "live"
# PAYPAL SUBSCRIPTION
PAYPAL_APP_ID=xxxxxxxxxxxx
PAYPAL_APP_SK=xxxxxxxxxxxx
PAYPAL_APP_MODE=test
产品
如果您想查看所有可能的选项
https://developer.paypal.com/docs/api/catalog-products/v1/#products_create
创建(产品)
$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);
计划
如果您想查看所有可能的选项
https://developer.paypal.com/docs/api/subscriptions/v1/#plans
创建(计划)
$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);
订阅
如果您想查看所有可能的选项
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions
创建(订阅)
$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' => 'leifer@test.com', '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);
暂停(订阅)
注意:您只能暂停状态为
ACTIVE
的订阅。
$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);