PayPal php 产品试用期「建议收藏」

PayPal php 产品试用期

大家好,又见面了,我是全栈君。

一.提供试用期

使用试用期,使订户可以在常规计费周期开始之前以免费或打折的价格试用您的产品。试用期结束后,订阅的常规计费期开始。每个计划最多可以有两个试用期。

以下样本请求显示了如何提供试用期。创建计划时,请使用这些示例来调整代码。

 

示例:音乐服务

本示例设置具有以下特征的试用期:

  • 第一个月$ 0。
  • 试用期后每月15美元。
curl -v –X POST https://api-m.sandbox.paypal.com/v1/billing/plans \
-H "Accept: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: PLAN-18062020-002" \
-d '{
     "name": "Premium Music Plus",
    "description": "A premium plan with music download feature",
    "product_id": "PROD-5RN21878H3527870P",
    "billing_cycles": [
        {
            "frequency": {
                "interval_unit": "MONTH",
                "interval_count": 1
            },
            "tenure_type": "TRIAL",
            "sequence": 1,
            "total_cycles": 1,
            "pricing_scheme": {
                "fixed_price": {
                    "value": "0",  
                    "currency_code": "USD"
                }
            }
        },
        {
            "frequency": {
                "interval_unit": "MONTH",
                "interval_count": 1
            },
            "tenure_type": "REGULAR",
            "sequence": 2,
            "total_cycles": 0,
            "pricing_scheme": {
                "fixed_price": {
                    "value": "15",
                    "currency_code": "USD"
                }
            }
        }
    ],
    "payment_preferences": {
        "auto_bill_outstanding": true,
        "payment_failure_threshold": 1
    }
 }'
 

示例:在线教程服务

本示例设置具有以下特征的试用期:

  • 首周$ 0免费试用。
  • 接下来的3周,每周5美元的优惠试用期。
  • 试用期后每周10美元。
curl -v –X POST https://api-m.sandbox.paypal.com/v1/billing/plans \
-H "Accept: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: PLAN-18062020-003" \
-d '{
     "name": "Music Tutorial Premium Plus",
    "description": "Offering a premium music tutorial with download feature",
    "product_id": "PROD-5RN21878H3527870P",
    "billing_cycles": [
        {
            "frequency": {
                "interval_unit": "WEEK",
                "interval_count": 1
            },
            "tenure_type": "TRIAL",
            "sequence": 1,
            "total_cycles": 1,
            "pricing_scheme": {
                "fixed_price": {
                    "value": "0",
                    "currency_code": "USD"
                }
            }
        },
        {
            "frequency": {
                "interval_unit": "WEEK",
                "interval_count": 1
            },
            "tenure_type": "TRIAL",
            "sequence": 2,
            "total_cycles": 3,
            "pricing_scheme": {
                "fixed_price": {
                    "value": "5",
                    "currency_code": "USD"
                }
            }
        },
        {
            "frequency": {
                "interval_unit": "WEEK",
                "interval_count": 1
            },
            "tenure_type": "REGULAR",
            "sequence": 3,
            "total_cycles": 0,
            "pricing_scheme": {
                "fixed_price": {
                    "value": "10",
                    "currency_code": "USD"
                }
            }
        }
    ],
    "payment_preferences": {
        "auto_bill_outstanding": true,
        "payment_failure_threshold": 1
    }
 }`

 

二 .订阅和试用按钮

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

    <!-- Identify your business so that you can collect the payments. -->
    <input type="hidden" name="business" value="alice@mystore.com">

    <!-- Specify a Subscribe button. -->
    <input type="hidden" name="cmd" value="_xclick-subscriptions">
    <!-- Identify the subscription. -->
    <input type="hidden" name="item_name" value="Alice's Weekly Digest">
    <input type="hidden" name="item_number" value="DIG Weekly">

    <!-- Set the terms of the regular subscription. -->
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="a3" value="5.00">
    <input type="hidden" name="p3" value="1">
    <input type="hidden" name="t3" value="M">

    <!-- Set recurring payments until canceled. -->
    <input type="hidden" name="src" value="1">

    <!-- Display the payment button. -->
    <input type="image" name="submit"
           src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribe_LG.gif"
           alt="Subscribe">
    <img alt="" width="1" height="1"
         src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

    <!-- Identify your business so that you can collect the payments. -->
    <input type="hidden" name="business" value="alice@mystore.com">

    <!-- Specify a Subscribe button. -->
    <input type="hidden" name="cmd" value="_xclick-subscriptions">

    <!-- Identify the subscription. -->
    <input type="hidden" name="item_name" value="Alice's Weekly Digest">
    <input type="hidden" name="item_number" value="DIG Weekly">

    <!-- Set the terms of the 1st trial period. -->
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="a1" value="0">
    <input type="hidden" name="p1" value="7">
    <input type="hidden" name="t1" value="D">

    <!-- Set the terms of the 2nd trial period. -->
    <input type="hidden" name="a2" value="5.00">
    <input type="hidden" name="p2" value="3">
    <input type="hidden" name="t2" value="W">

    <!-- Set the terms of the regular subscription. -->
    <input type="hidden" name="a3" value="49.99">
    <input type="hidden" name="p3" value="1">
    <input type="hidden" name="t3" value="Y">

    <!-- Set recurring payments until canceled. -->
    <input type="hidden" name="src" value="1">

    <!-- Display the payment button. -->
    <input type="image" name="submit"
           src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribe_LG.gif"
           alt="Subscribe">
    <img alt="" width="1" height="1"
         src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
</body>
</html>

页面图示

PayPal php 产品试用期「建议收藏」

点击后效果图:

PayPal php 产品试用期「建议收藏」

代码示例1;

 /**
  * Create billing plan at paypal
  *
  * @param $name
  * @param $description
  * @param $amount
  * @param string $returnUrl
  * @param string $returnCancel
  * @param int $setupFee
  * @param bool $isTrial
  * @param string $currency
  * @param string $planType
  * @param string $definitionName
  * @param string $definitionType
  * @param string $definitionFrequency
  * @param string $definitionFrequencyInterval
  * @param string $definitionCycles
  * @param string $trialDefinitionName
  * @param string $trialDefinitionType
  * @param string $trialDefinitionFrequency
  * @param string $trialDefinitionFrequencyInterval
  * @param string $trialDefinitionCycles
  * @param string $trialDefinitionAmount
  * @return string
  */
function create($name, $description, $amount, $returnUrl = '', $returnCancel = '', $setupFee = 0, $isTrial = false, $currency = 'USD', $planType = 'fixed',
                $definitionName = 'Regular Payments', $definitionType = 'REGULAR', $definitionFrequency = 'Month', $definitionFrequencyInterval = '1', $definitionCycles = '12',
                $trialDefinitionName = 'Trial Period', $trialDefinitionType = 'TRIAL', $trialDefinitionFrequency = '0', $trialDefinitionFrequencyInterval = '0', $trialDefinitionCycles = '0',
                $trialDefinitionAmount = '0')
{
    $plan = new Plan();
    $plan->setName($name)->setDescription($description)->setType($planType);
    $paymentDefinition = new PaymentDefinition();
    $paymentDefinition->setName($definitionName)
        ->setType($definitionType)
        ->setFrequency($definitionFrequency)
        ->setFrequencyInterval($definitionFrequencyInterval)
        ->setCycles($definitionCycles)
        ->setAmount(new Currency(array('value' => $amount, 'currency' => $currency)));
    $plan->setPaymentDefinitions(array($paymentDefinition));

    if ($isTrial) {
        $paymentDefinitionTrial = new PaymentDefinition();
        $paymentDefinitionTrial->setName($trialDefinitionName)
            ->setType($trialDefinitionType)
            ->setFrequency($trialDefinitionFrequency)
            ->setFrequencyInterval($trialDefinitionFrequencyInterval)
            ->setCycles($trialDefinitionCycles)
            ->setAmount(new Currency(array('value' => $trialDefinitionAmount, 'currency' => $currency)));
        $plan->addPaymentDefinition($paymentDefinitionTrial);
    }

    $merchantPreferences = new MerchantPreferences();
    $merchantPreferences->setReturnUrl($returnUrl)
        ->setCancelUrl($returnCancel)
        ->setAutoBillAmount("yes")
        ->setInitialFailAmountAction("CONTINUE")
        ->setMaxFailAttempts("0")
        ->setSetupFee(new Currency(array('value' => $setupFee, 'currency' => $currency)));

    $plan->setPaymentDefinitions(array($paymentDefinition));
    $plan->setMerchantPreferences($merchantPreferences);
    $result = $plan->create($this->getAdapter()->getApiContext());
    if ($result) {
        return ['plan' => $result, 'id' => $result->getId(), 'state' => $result->getState(), 'created' => $result->getCreateTime()];
    }
    return $result;
}

在使用使用期时;一定要记得把第一次扣费的设为0:否则每次都正常订阅的扣费

 $this->paypal->set_merchant_preferences($returnurl, $cancelurl, 'YES', 'CONTINUE', '0', 0); // $price 设置第一次订阅扣款金额***, 默认0表示不扣款
public function set_merchant_preferences($return_url, $cancel_url, $auto_bill_amount = "NO", $initial_fail_amount_action = "CANCEL",
                                             $max_fail_attempts = 0, $agreement_fees = 0)
    {

        $this->merchantPreferences = new MerchantPreferences();
        $this->merchantPreferences->setReturnUrl($return_url)
            ->setCancelUrl($cancel_url)
            ->setAutoBillAmount($auto_bill_amount)
            ->setInitialFailAmountAction($initial_fail_amount_action)
            ->setMaxFailAttempts($max_fail_attempts)
            ->setSetupFee(new Currency(array('value' => $agreement_fees, 'currency' => config_item("currency"))));
        $this->plan->setMerchantPreferences($this->merchantPreferences);
        return;
    }

参考:https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/html-example-subscribe/#trial-periods

https://hotexamples.com/zh/examples/paypal.api/Plan/setPaymentDefinitions/php-plan-setpaymentdefinitions-method-examples.html

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/111560.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • Python fillna_pandas fillna 指定列

    Python fillna_pandas fillna 指定列对我来说工作:df.ix[df[‘Type’]==’Dog’,’Killed’]=df.ix[df[‘Type’]==’Dog’,’Killed’].fillna(2.25)print(df)TypeKilledSurvived0Dog5.0021Dog3.0042Cat1.0073Dog2.2534cowNaN2如果系列需要fillna–因…

  • MySQL 常用语句_MySQL常用命令

    MySQL 常用语句_MySQL常用命令数据库#查看所有的数据库SHOWDATABASES;#创建一个数据库CREATEDATABASEk;#删除一个数据库DROPDATABASEk;#使用这个数据库USEk;表#查看所有的表SHOWTABLES;#创建一个表CREATETABLEn(idINT,nameVARCHAR(10));CREATETABLEm(idINT,…

  • 七牛云文件上传_七牛云价格

    七牛云文件上传_七牛云价格七牛云上传图片到七牛云并返回图片URL鸣谢’追逐盛夏流年’:https://blog.csdn.net/j1231230/article/details/80061834在开发项目的时候,经常会用到上传图片的功能,如果把图片全都存放在项目路径下,会导致项目越来越臃肿,因此可以考虑把图片上传交给第三方处理,此处我们采用七牛云进行图片存储。一.七…

  • 实现redhat的完全自动化安装

    实现redhat的完全自动化安装

  • 免费已备案二级域名_二级免备案域名

    免费已备案二级域名_二级免备案域名今天给大家推荐一个免备案的免费二级域名注册平台。DYUNS域名网-永久免费域名_免备案域名只需要一个邮箱,就能注册到自己的二级域名,非常方便。提供”icu.ltd”等超短域名注册服务,非常有利于用户访问与记忆。平台还提供了免费的CDN+防御+免备案服务,这是其他平台都没有的,也是我选择它的理由之一。管理也非常方便,后台一键就能完成自助删改解析等操作。官方客服的服务也是十分的到位,体验很好。大家也可以自行注册体验哦!…

  • linux文件共享 samba_docker阿里云盘

    linux文件共享 samba_docker阿里云盘我这里用的yum库安装的samba所有服务三步走战略,关闭防火墙,关闭沙盒,配置IP地址配置IP重启服务创建用户haha,hehe配置共享samba用户创建共享目录,赋予权限,进入到主smb文件进行配置,保存退出后配置别名配置共享目录,权限,加入用户保存退出先用Windows客户机进行验证将IP改为1.10后因为设置的拒绝无法访问修改IP地址后可以进行访问创建空文件,进行拖拽,…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号