billythekid/v12finance

V12 零售金融 REST API 的 PHP Wwrapper

0.0.1 2018-10-16 15:02 UTC

This package is auto-updated.

Last update: 2024-09-20 11:47:25 UTC


README

由于我为该项目开发的客户决定使用另一家金融提供商,因此该项目处于短暂的休息状态,因此完成度为70%!

您可以使用 composer require billythekid/v12finance 在自己的项目中安装它

欢迎提交缺少的类的PR,或者我最终会将它作为一个副项目来完成,希望如此。

这是API文档

下面是一些使用此API的示例代码

<pre><?php
include('../vendor/autoload.php');

use billythekid\v12finance\models\Customer;
use billythekid\v12finance\models\exceptions\InvalidTelephoneException;
use billythekid\v12finance\models\FinanceProduct;
use billythekid\v12finance\models\Order;
use billythekid\v12finance\models\OrderLine;
use billythekid\v12finance\models\requests\ApplicationRequest;
use billythekid\v12finance\models\requests\ApplicationStatusRequest;
use billythekid\v12finance\models\requests\FinanceProductListRequest;
use billythekid\v12finance\models\responses\FinanceProductListResponse;
use billythekid\v12finance\models\Retailer;
use billythekid\v12finance\V12FinanceClient;

$faker    = Faker\Factory::create();
$retailer = new Retailer(
    'YOUR AUTHENTICATION KEY',
    "YOUR RETAILER GUID",
    'YOUR RETAILER ID');

$client = new V12FinanceClient();

// Get all the products available to this retailer
$productListRequest = new FinanceProductListRequest($retailer);
/** @var FinanceProductListResponse $products */
$products = $client->getRetailerFinanceProducts($productListRequest);

/** @var FinanceProduct $product */
$product = $products->getFinanceProducts()[0];

echo json_encode($product, JSON_PRETTY_PRINT) . "\n\n";
$customer = (new Customer())
    ->setEmailAddress($faker->email)
    ->setFirstName($faker->firstName)
    ->setLastName($faker->lastName);
try
{
  $customer->setHomeTelephone(['code' => '01234', 'number' => '567890'])
      ->setMobileTelephone(['code' => '07777', 'number' => '888999']);
} catch (InvalidTelephoneException $e)
{  /* nothing to do here */
}

$lineItems = [
    (new OrderLine())
        ->setItem($faker->words(3, true))
        ->setPrice($faker->randomFloat(2, 100, 1000))
        ->setQty($faker->numberBetween(1, 5))
        ->setSku('item1sku'),
    (new OrderLine())
        ->setItem($faker->words(3, true))
        ->setPrice($faker->randomFloat(2, 100, 1000))
        ->setQty($faker->numberBetween(1, 5))
        ->setSku('item2sku'),
];

echo json_encode($lineItems, JSON_PRETTY_PRINT) . "\n\n";

$totalPrice = ($lineItems[0]->getQty() * $lineItems[0]->getPrice()) + ($lineItems[1]->getQty() * $lineItems[1]->getPrice());

echo "Total Price: {$totalPrice}\n\n";

$salesReference = $faker->word;
$order          = (new Order())
    ->setCashPrice($totalPrice)
    ->setDeposit(round($totalPrice / 2))
    ->setProductId($product->getProductId())
    ->setProductGuid($product->getProductGuid())
    ->setDuplicateSalesReferenceMethod("Ignore")
    ->setIpAddress(@$_SERVER['REMOTE_ADDR'])
    ->setLines($lineItems)
    ->setSalesReference($salesReference);
//      ->setSalesReference('testing PHP wrapper');

echo json_encode($order, JSON_PRETTY_PRINT) . "\n\n";

$applicationRequest = new ApplicationRequest($retailer, $order, $customer, false);
$response           = $client->submitApplication($applicationRequest);

//  $statusRequest = new ApplicationStatusRequest($retailer, "SOME_APPLICATION_ID");
//  $response      = $client->checkApplicationStatus($statusRequest);


//$headers = $client->headers('GetRetailerFinanceProducts', $productListRequest);

//foreach ($headers as $name => $values) {
//  echo $name . ': ' . implode(', ', $values) . "\r\n";
//}

echo json_encode($response, JSON_PRETTY_PRINT);