breadhead/paddle

Breadhead版本的Paddle.com API PHP库

1.2.1 2020-03-06 10:48 UTC

This package is auto-updated.

Last update: 2024-09-06 21:35:52 UTC


README

此库提供了一种方便的方式,可以从PHP代码中查询Paddle API。

要求

PHP 5.3或更高版本。

通过Composer安装

composer req breadhead/paddle

入门指南

要与Paddle API交互,您需要创建一个API对象,并使用vendorId / vendorApiKey进行授权

$api = new \Breadhead\Paddle\Api();
$api->authorizeVendor($vendorId, $vendorAuthCode);

可选地,您可以设置HTTP超时(默认为30秒)

$api->setTimeout(60);

在创建新的API对象时,也可以同时设置授权和超时

$api = new \Breadhead\Paddle\Api($vendorId, $vendorAuthCode, 60);

generateLicense()方法的使用示例

// define $vendorId and $vendorAuthCode first
$api = new \Breadhead\Paddle\Api($vendorId, $vendorAuthCode, 60);
$productId = 100;
$licenseCode = $api->generateLicense($productId);

常见异常

所有方法都可以抛出以下类型的\Exception异常

  • 1XX - API响应错误

  • code: 100 message: '无法找到请求的许可证'

  • code: 101 message: '方法调用错误'

  • code: 102 message: 'API密钥错误'

  • code: 103 message: '时间戳太旧或无效'

  • code: 104 message: '许可证代码已被使用'

  • code: 105 message: '许可证代码未激活'

  • code: 106 message: '无法找到请求的激活'

  • code: 107 message: '您没有权限访问此资源'

  • code: 108 message: '无法找到请求的产品'

  • code: 109 message: '提供的货币无效'

  • code: 110 message: '无法找到请求的购买'

  • code: 111 message: '无效的认证令牌'

  • code: 112 message: '无效的验证令牌'

  • code: 113 message: '解密字符串上的填充无效'

  • code: 114 message: '无效或重复的联盟'

  • code: 115 message: '无效或缺少联盟佣金'

  • code: 116 message: '缺少一个或多个必需的参数'

  • code: 117 message: '提供的过期时间不正确'

  • 2XX - 一般错误

  • code: 200 message: 'CURL错误'

  • code: 201 message: 'HTTP响应代码不正确'

  • code: 202 message: 'API响应不正确'

  • code: 203 message: '超时必须是正整数'

  • code: 204 message: '未提供供应商凭证'

可用方法

生成普通产品的支付链接

string generateProductPayLink (int $productId, [array $optionalArguments = array()])

参数

  • int $productId - 产品ID
  • array $optionalArguments - 可选参数的关联数组
  • string 'title' - 覆盖产品标题
  • string 'imageUrl' - 覆盖产品图片
  • float 'price' - 覆盖产品价格
  • string 'returnUrl' - 交易完成后要重定向的URL
  • bool 'discountable' - 是否可以应用优惠券
  • string 'couponCode' - 优惠券代码
  • bool 'lockerVisible' - 产品是否在用户的锁箱中可见
  • bool 'quantityVariable' - 产品数量是否可以由用户更改
  • string 'paypalCancelUrl' - PayPal交易取消时要重定向的URL
  • int 'expires' - 结账过期日期,时间戳
  • bool 'isPopup' - 结账是否作为弹出窗口显示
  • string 'parentUrl' - 点击结账弹出窗口上的关闭按钮时要重定向的URL
  • array 'affiliates' - 每个元素都应该包含 affiliate_id 作为键,以及 affiliate_commission 作为值。
  • 佣金值应该是浮点数,所以佣金 '0.1' 等于10%。
  • array 'stylesheets' - 每个元素都应该包含样式表类型作为键,以及代码作为值

类型为\InvalidArgumentException的验证异常

  • code: 300 message: '$productId必须是正整数'
  • code: 301 message: '$title必须是字符串'
  • code: 302 message: '$imageUrl必须是有效的URL'
  • code: 303 message: '$price必须是数字'
  • code: 304 message: '$price不能为负数'
  • 代码:305 信息:'$returnUrl 必须是一个有效的 URL'
  • 代码:306 信息:'$paypalCancelUrl 必须是一个有效的 URL'
  • 代码:307 信息:'$expires 必须是一个有效的时间戳'
  • 代码:308 信息:'$expires 必须在未来'
  • 代码:309 信息:'$parentUrl 必须是一个有效的 URL'
  • 代码:310 信息:'$affiliates 必须是一个数组'
  • 代码:311 信息:'请将 $affiliates 提供为 key->value 包含的数组,格式为 vendorId->vendorCommission'
  • 代码:312 信息:'$stylesheets 必须是一个数组'
  • 代码:313 信息:'请将 $stylesheets 提供为 key->value 包含的数组,格式为 stylesheetType->stylesheetCode'
  • 代码:314 信息:'$webhookUrl 只能用于自定义产品'

为自定义(不在 Paddle 数据库中存在的)产品生成支付链接

string generateCustomProductPayLink (string $title, float $price, string $imageUrl, string $webhookUrl, array $optionalArguments)

参数

  • 字符串 $title - 自定义产品的标题
  • 浮点数 $price - 自定义产品的价格
  • 字符串 $imageUrl - 自定义产品的图片
  • 字符串 $webhookUrl - 自定义产品的 webhook_url
  • array $optionalArguments - 可选参数的关联数组
  • string 'returnUrl' - 交易完成后要重定向的URL
  • bool 'lockerVisible' - 产品是否在用户的锁箱中可见
  • bool 'quantityVariable' - 产品数量是否可以由用户更改
  • string 'paypalCancelUrl' - PayPal交易取消时要重定向的URL
  • int 'expires' - 结账过期日期,时间戳
  • bool 'isPopup' - 结账是否作为弹出窗口显示
  • string 'parentUrl' - 点击结账弹出窗口上的关闭按钮时要重定向的URL
  • array 'affiliates' - 每个元素都应该包含 affiliate_id 作为键,以及 affiliate_commission 作为值。
  • 佣金值应该是浮点数,所以佣金 '0.1' 等于10%。
  • array 'stylesheets' - 每个元素都应该包含样式表类型作为键,以及代码作为值

类型为\InvalidArgumentException的验证异常

  • code: 301 message: '$title必须是字符串'
  • code: 302 message: '$imageUrl必须是有效的URL'
  • code: 303 message: '$price必须是数字'
  • code: 304 message: '$price不能为负数'
  • 代码:305 信息:'$returnUrl 必须是一个有效的 URL'
  • 代码:306 信息:'$paypalCancelUrl 必须是一个有效的 URL'
  • 代码:307 信息:'$expires 必须是一个有效的时间戳'
  • 代码:308 信息:'$expires 必须在未来'
  • 代码:309 信息:'$parentUrl 必须是一个有效的 URL'
  • 代码:310 信息:'$affiliates 必须是一个数组'
  • 代码:311 信息:'请将 $affiliates 提供为 key->value 包含的数组,格式为 vendorId->vendorCommission'
  • 代码:312 信息:'$stylesheets 必须是一个数组'
  • 代码:313 信息:'请将 $stylesheets 提供为 key->value 包含的数组,格式为 stylesheetType->stylesheetCode'
  • 代码:315 信息:'$webhookUrl 必须是一个有效的 URL'
  • 代码:316 信息:'$discountable 不允许用于自定义产品'
  • 代码:317 信息:'$couponCode 不允许用于自定义产品'
  • 代码:318 信息:'$productId 不允许用于自定义产品'

为框架产品生成许可证代码

string generateLicense (int $productId)

参数

  • int $productId - 产品ID

类型为\InvalidArgumentException的验证异常

  • code: 300 message: '$productId必须是正整数'

获取包含每个产品详细信息的分页产品列表

array getProducts ([int $limit = 1], [int $offset = 0])

参数

  • 整数 $limit - 返回产品的数量
  • 整数 $offset - 从第一个产品开始的偏移量

返回值

返回数组包含

  • 整数 'total' - 产品总数
  • 整数 'count' - 返回产品的数量
  • 数组 'products' - 返回的产品,其中每个产品包含
  • 整数 'id' - 产品的 id
  • 字符串 'name' - 产品的名称
  • 字符串 'description' - 产品的描述
  • 浮点数 'basePrice' - 产品的基准价格
  • 浮点数 'salePrice' - 产品的销售价格
  • 数组 'screenshots' - 产品的截图
  • 字符串 'icon' - 产品的图片

类型为\InvalidArgumentException的验证异常

  • 代码:319 信息:'$limit 必须是一个正整数'
  • 代码:320 信息:'$offset 必须是一个非负整数'

获取客户详情数组

array generateCustomersReport ([int $productId = null])

参数

  • 整数 $productId - 要创建报告的产品的 id,如果不提供,则报告将包含所有产品的数据

返回值

返回数组包含

  • 字符串 'fullName' - 客户的全名
  • 字符串 'email' - 客户的电子邮件地址

类型为\InvalidArgumentException的验证异常

  • code: 300 message: '$productId必须是正整数'

获取许可证激活详情数组

激活将在发生后的第二天报告 - 因此今天发生的任何激活将不会包括在内

array generateLicenseActivationsReport ([int $productId = null], [int $startTimestamp = null], [int $endTimestamp = null])

参数

  • 整数 $productId - 要创建报告的产品的 id,如果不提供,则报告将包含所有产品的数据
  • 整数 $startTimestamp - 报告开始时间
  • 整数 $endTimestamp - 报告结束日期

返回值

返回数组包含

  • 字符串 'licenseCode' - 许可证代码
  • 字符串 'activationDate' - 激活日期
  • 字符串 'customerIp' - 客户 IP
  • 字符串 'customerEmail' - 客户电子邮件

类型为\InvalidArgumentException的验证异常

  • code: 300 message: '$productId必须是正整数'
  • 代码:321 信息:'$startTimestamp 必须是一个时间戳'
  • 代码:322 信息:'$endTimestamp 必须是一个时间戳'

获取订单详情数组

array generateOrdersReport ([int $productId = null], [int $startTimestamp = null], [int $endTimestamp = null])

参数

  • 整数 $productId - 要创建报告的产品的 id,如果不提供,则报告将包含所有产品的数据
  • 整数 $startTimestamp - 报告开始时间
  • 整数 $endTimestamp - 报告结束日期

返回值

返回数组包含

  • 整数 'orderId' - 订单的 id
  • 字符串 'productName' - 产品的名称
  • 浮点数 'yourEarnings' - 你的收益
  • 字符串 'earningsCurrency' - 收益货币
  • 字符串 'saleDate' - 销售日期

类型为\InvalidArgumentException的验证异常

  • code: 300 message: '$productId必须是正整数'
  • 代码:321 信息:'$startTimestamp 必须是一个时间戳'
  • 代码:322 信息:'$endTimestamp 必须是一个时间戳'

获取发送的许可证详情数组

array generateSentLicensesReport ([int $productId = null])

参数

  • 整数 $productId - 要创建报告的产品的 id,如果不提供,则报告将包含所有产品的数据

返回值

返回数组包含

  • 字符串 'customerName' - 客户的全名
  • 字符串 'customerEmail' - 客户的电子邮件地址
  • 字符串 'productName' - 产品的名称
  • 字符串 'licenseCode' - 许可证代码

类型为\InvalidArgumentException的验证异常

  • code: 300 message: '$productId必须是正整数'

生成用于调用其他 API 方法的凭据

array generateAuthCode (string $vendorEmail, string $vendorPassword)

参数

  • 字符串 $vendorEmail
  • 字符串 $vendorPassword

返回值

返回数组包含

  • 整数 'vendorId'
  • 字符串 'vendorAuthCode'

类型为\InvalidArgumentException的验证异常

  • 代码:323 信息:'$vendorEmail 必须是有效的'

注册外部应用程序并接收授权代码,该应用程序可以使用它来调用 API 方法

string registerExternalApplication (string $applicationName, string $applicationDescription, string $applicationIconUrl)

类型为\InvalidArgumentException的验证异常

  • 代码:324 信息:'$applicationIconUrl 必须是一个有效的 URL'

获取供应商公钥

string getVendorPublicKey ()