faWaterk/faWaterk-sdk

简化Fawaterk API集成。

此包的官方仓库似乎已消失,因此该包已被冻结。

1.2 2018-09-21 01:21 UTC

This package is auto-updated.

Last update: 2022-03-21 15:08:15 UTC


README

简化Fawaterk API集成。

如何使用?

非常简单;

首先,我们需要通过composer引入SDK。

composer require faWaterk/faWaterk-sdk

然后,在您的PHP代码中,您需要创建一个 \Fawaterk\Fawaterk 类的实例,然后您可以调用几个方法来设置API所需的数据。

需要哪些数据?如何格式化它们?

为了为您和您的客户创建发票,我们需要以下几项必要信息

  1. vendorKey => 您需要在自己的账户中创建一个,您需要在https://app.fawaterk.com上创建账户,这是完全免费的!
  2. customer => 这是关于尝试为订单付款的客户的某些信息。
  • 客户是一个具有4个键的数组

-- name

-- email

-- phone

-- address

  1. currency => 这是将要使用的货币(您的客户将支付的货币)。

-- 目前我们支持3种货币,分别是EGP、SAR和EUR。未来还将添加更多。

  1. cartItems => 订单项的数组。每个项都是一个具有3个键的数组

-- name

-- quantity

-- price

  1. shipping => 运输价值的浮点数

  2. cartTotal => 客户应支付的总金额的浮点数(含税费和运输费)

  3. redirectUrl => 客户成功支付发票后应重定向到的URL字符串

工作示例

以下是带有实际代码的完整工作示例。

<?php

use \Fawaterk\Fawaterk;
...

// prepare the data in the correct format.
$cartItems = [
    [ 'name' => 'Item 1', 'price' => 5, 'quantity' => 1],
    [ 'name' => 'Item 2', 'price' => 10, 'quantity' => 2]
];
$customer = [
    'name'    => 'John Smith',
    'email'   => 'john.smith@example.com',
    'phone'   => '1234567890',
    'address' => '21st South Park Avenue'
];
$shipping = 2;
$cartTotal = 27;
$redirectUrl = "https://fawaterk.com";
$currency = 'EGP';

$fawaterk = new Fawaterk;

// fill the object with the correct data
$fawaterk->setVendorKey('YOUR_VENDOR_KEY_HERE')
         ->setCartItems($cartItems)
         ->setCustomer($customer)
         ->setShipping($shipping)
         ->setCartTotal($cartTotal)
         ->setRedirectUrl($redirectUrl)
         ->setCurrency($currency);

// send the request and receive the invoice url
$invoiceUrl = $fawaterk->getInvoiceUrl();

// redirect the user to the invoice url
header("Location: {$invoiceUrl}");

即将推出的功能(即将推出)

  • 更多货币
  • 税费