usameavci/papara-sdk

此包已被废弃,不再维护。未建议替代包。

PaPara简单集成类

1.1.0 2017-03-29 20:58 UTC

This package is not auto-updated.

Last update: 2020-08-22 05:56:45 UTC


README

PaPara(电子货币发行商)的简单集成包

Packagist

安装

composer require usameavci/papara-sdk

入门

    // Require compsoers autoload file
    require 'vendor/autoload.php';

    // Defining namespace usings
    use UsameAvci\PaPara\{ PaPara, ShoppingVoucher, ShoppingVoucherEntity, PaParaException };


    // Set environments [ default: test ]
    PaPara::setEnvironment([
        "test" => [
            "url" => "https://test.papara.com/posservice/ApiRequest.asmx",
            "username" => "...",
            "key" => "...",
            "walletno" => "...",
            "referansId" => "...",
            "secret_key" => "...",
        ],
        "prod" => [
            "url" => "https://account.papara.com/posservice/ApiRequest.asmx",
            "username" => "...",
            "referansId" => "...",
            "walletno" => "...",
            "key" => "...",
            "secret_key" => "...",
        ],
    ]);

创建交易

    // Creating Papara Instance
    $transaction = new Papara();

    $transaction
        // Setting order id
        ->setOrderId('ORDER-' . rand(1, 9999))
        // Setting discount amount
        ->setDiscount(0)
        // Setting return url
        ->setUrl('https://example.com/payment-result');


        // Creating shopping voucher entitiy
        $shoppingVoucherEntity = new ShoppingVoucherEntity;

            $shoppingVoucherEntity
                // Setting cart id
                ->setShoppingId(rand(1, 100))
                // Setting product name
                ->setProductName($_GET['ProductName'])
                // Setting product quantity
                ->setQuantity($_GET['Quantity'])
                // Setting product amount
                ->setAmount(15)
                // Setting total amount | This method is optional,
                // default value is (quantity * amount) when this method is not used
                ->setTotalAmount(1)
                // Setting product's category name
                ->setCategoryName('Plans');

        // Adding shopping voucher entity to shopping cart
        $shoppingVoucher = new ShoppingVoucher;

            $shoppingVoucher
                // Adding entities to cart
                ->add($shoppingVoucherEntity);

        // Setting shopping vouchers
        $transaction->setShoppingVoucher($shoppingVoucher);

获取响应

    try {
        $response = $transaction->send();
        var_dump($response);
    } catch (PaParaException $e) {
        echo $e->getMessage();
    }