此包的最新版本(1.1.4)没有提供许可信息。

为Nelnet系统提供用户友好的界面。

1.1.4 2016-04-08 18:25 UTC

This package is not auto-updated.

Last update: 2024-10-02 08:41:43 UTC


README

注意:任何返回值超过50的“Nelnet状态”实际上都不是来自NELNET。

安装

安装此库最简单的方法是通过composer,但需要您已将 git 配置为使用SSH密钥

将以下内容添加到您的项目中的 composer.json 文件中

"require": {
    "ritproduction/nelnet": "dev-master"
},
"repositories": [
    {
        "type": "vcs",
        "url": "git@bitbucket.org:ritproduction/nelnet-library.git"
    }
]

然后,composer自动加载器会处理剩余的部分。

如果您还没有使用composer(您应该使用 ),您只需将 仓库克隆到您希望放置的文件夹中,然后

require_once('path/to/nelnet/src/autoload.php');

用法

以下代码是您开始所需的所有内容

<?php
use RIT\Prod\Nelnet as Nelnet;

require_once("path/to/Nelnet/autoload.php");

$nelnet = new Nelnet\Nelnet();
$nelnet->orderType = "[Your Order Type]";
$nelnet->sharedSecret = "[Your Shared Secret]";
$nelnet->redirectUrl = "[Your Confirmation Page]";
$nelnet->setNelnetEnvironment("[Staging | Production]");

$params = array(
    "id" => [This instance's ID],
    "amount" => (XXX * 100), // dollars (X) times 100 to convert to pennies
);

$request = $nelnet->buildRequest();
$request->send($params);

以及您的确认页面

<?php
use RIT\Prod\Nelnet as Nelnet;

require_once("path/to/Nelnet/autoload.php");

$nelnet = new Nelnet\Nelnet();
$nelnet->sharedSecret = "[Your Shared Secret]";
$response = $nelnet->buildResponse($_GET);

您甚至可以将Autoload和Nelnet初始化拆分到一个公共的共享文件中,并在这里配置它。然后您只需要在适当的页面上构建请求和响应

header.php

<?php
use RIT\Prod\Nelnet as Nelnet;

require_once("path/to/Nelnet/autoload.php");

$nelnet = new Nelnet\Nelnet();
$nelnet->orderType = "[Your Order Type]";
$nelnet->sharedSecret = "[Your Shared Secret]";
$nelnet->redirectUrl = "[Your Confirmation Page]";
$nelnet->setNelnetEnvironment("[Staging | Production]");

form-handler.php

<?php
include ('/path/to/header.php');
$params = array(
    "id" => [This instance's ID],
    "amount" => (XXX * 100),
    "email" => [User's email],
);

$request = $nelnet->buildRequest();
$request->send($params);

confirmation.php

<?php
include('path/to/header.php');
...
$response = $nelnet->buildResponse($_GET);
...
//print human readble status
$statuses = $response->config->statuses;
$current_status = $statuses[$response->transactionStatus];
print $current_status->getDetails();

自定义用户选择

(userChoice1, userChoice2, userChoice3, userChoice4, userChoice5)

这些是内置到Nelnet中的,可以用来向Nelnet传递额外信息,并在支付后通过URL返回。使用此功能的一个主要原因是发送web表单的节点ID,这样您就可以使用一个单独的确认页面。

form-handler.php

<?php
$params = array(
	'id'		=> $submission_id,
	'amount'	=> $amount,
	'email'		=> $email,
	'extras'	=> [$webform_node_id, $etc]
);
$request = $nelnet->buildRequest();
$request->send($params);

confirmation.php

<?php
$response		= $nelnet->buildResponse($_GET);
$userChoices	= $response->extras;
$userChoice1	= $userChoices[0];
$userChoice2	= $userChoices[1];
// etc, be sure to check isset