1.1.2 2022-12-03 21:30 UTC

This package is not auto-updated.

Last update: 2024-09-22 05:56:57 UTC


README

用法

I- 安装

composer require spare-technologies/php-sdk "^1.1"

将这些文件包含到您的应用程序中,并在文件顶部执行此操作

require __DIR__ . '/vendor/autoload.php';

II- 生成ECC密钥对

use Helpers\Crypto\SpCrypto;

public class MyClass {
    $keys = SpCrypto::GenerateKeyPair();
    
    echo "Private key \n" . nl2br($keys->getPrivateKey());
    echo "\n\n";
    echo "Public key \n" . nl2br($keys->getPublicKey())
}

III- 创建第一个支付请求

use Helpers\Security\DigitalSignature\EccSignatureManager;
use Helpers\Serialization\SpSerializer;
use Payment\Client\SpPaymentClient;

public class MyClass {

    // Business ECC private key
    public static string $privateKey = "";

    // Spare ECC public key
    public static string $serverPublicKey = "";

    public static function createPayment(): void {

        // Configure client
        $clientOptions = new SpPaymentClientOptions(
        "https://payment.tryspare.com",
        "Your app id",
        "Your API key"
        );

        $client = new SpPaymentClient($clientOptions);

        // Initialize payment
        $paymentRequest = new SpPaymentRequest();
        $paymentRequest->setAmount(10.0);
        $paymentRequest->setDescription("Test payment");
        $paymentRequest->setOrderId("8jwaQ");

        // Sign the payment 
        $signature = EccSignatureManager::Sign($paymentRequest->toJonsString(), $privateKey);

        // Create payment
        $paymentResponse = $this->paymentClient->CreateDomesticPayment($paymentRequest, $signature);

        // To verify signature of the created payment 
        if (EccSignatureManager::Verify($serverPublicKey, $paymentResponse->getPayment()->toJonsString(), createPayment->getSignature())) {
            // signature verified
        }
    }
}