tarekhammad/faw-sdk

简化Fawaterk API集成。

dev-main 2022-11-09 00:26 UTC

This package is auto-updated.

Last update: 2024-09-09 04:34:29 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}");

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

  • 更多货币
  • 税费