hashbang/securepay

PHP SecurePay API

v1.0.6 2020-08-30 23:56 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:18:35 UTC


README

注意:此模块已过时,因为SecurePay已从SOAP XML API迁移到REST 请参阅SecurePay API 以与SecurePay通信

以下文档提供用于向后兼容现有SOAP XML请求,这些请求使用旧的用户名/密码系统

非常简单的 SecurePay.com.au API for PHP。

安全支付服务是一个相当可靠且文档齐全的信用卡网关。

您将需要一个现有的用户名和密码(或测试账户)来使用此模块。

安装

下载此GIT存储库并将其复制到您的应用程序目录。

或者,使用 Composer 进行安装。

示例

完整示例

<?php
include('securepay.php');

$sp = new SecurePay('username','password');
$sp->TestMode(); // Remove this line to actually preform a transaction

$sp->TestConnection();
print_r($sp->ResponseXml);

$sp->NameOnCard = 'John Citizen'; // optional
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
if ($sp->Valid()) { // Is the above data valid?
	$response = $sp->Process();
	if ($response == SECUREPAY_STATUS_APPROVED) {
		echo "Transaction was a success\n";
	} else {
		echo "Transaction failed with the error code: $response\n";
		echo "XML Dump: " . print_r($sp->ResponseXml,1) . "\n";
	}
} else {
	die("Your data is invalid\n");
}
?>

全局

以下示例均展示了启动基本PHP设置所需的步骤。显然,我们首先需要加载库

<?php
include('securepay.php');

创建一个新的SecurePay对象

$sp = new SecurePay('username','password');

或者

$sp = new SecurePay();
$sp->Login('username','password');

测试与服务器之间的连接

if ($sp->TestConnection()) {
	echo "Server is working\n";
} else {
	echo "Server is Down\n";
}

启用测试模式(可选)

$sp->TestMode();

或者

$sp->TestMode(TRUE);

检查所有提供的数据是否有效(快速方法)

if ($sp->Valid()) {
	echo "Everything is valid\n";
} else {
	echo "Something is wrong\n";
}

或者,您可以单独分解每个有效性测试

if (!$sp->ValidCc()) {
	echo "Credit Card Number is invalid\n";
} elseif (!$sp->ValidExpiryDate()) {
	echo "Expiry Date is invalid\n";
} elseif (!$sp->ValidCvv()) {
	echo "CVV is invalid\n";
} elseif (!$sp->ValidChargeAmount()) {
	echo "Charge Amount is invalid\n";
} elseif (!$sp->ValidChargeCurrency()) {
	echo "Charge Currency is invalid\n";
} elseif (!$sp->ValidOrderId()) {
	echo "Order ID is invalid\n";
} else {
	echo "All data is valid\n";
}

处理支付

// Charge the credit card '462834666666' '$123' US dollars. The card expires on '07/09', has the CVV code '32' and the local order ID is 'ORD34234'.
$sp->Process(123, 'USD', '462834666666', '07/09', '321', 'ORD34234');

或者

// Charge the credit card '462834666666' '$123' US dollars. The card expires on '07/09', has the CVV code '32' and the local order ID is 'ORD34234'.
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
$sp->Process();

预先授权支付

// This is the same process as passing a regular payment but the last parameter indicates that it should be treated as a PreAuth transaction
$sp->Process(123, 'USD', '462834666666', '07/09', '321', 'ORD34234', TRUE);

或者

// Exactly the same as a regular charge but with PreAuth = 1
$sp->PreAuth = 1;
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
$sp->Process();
$preauthid = $sp->PreAuthId; // $preauthid contains the ID used by SecurePay (use this when finalizing a PreAuth)

收费预先授权支付

$sp->PreAuth = 1;
$sp->PreAuthID = $preauthid; // The ID we got in the above process
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->OrderId = 'ORD34234'; // NOTE this must match the OrderID used in the above process
$sp->Process();

设置重复支付

// Charge the credit card '462834666666' '$123' US dollars every month for 6 months.
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
$sp->SetupRepeat('monthly', 6); // Second arg is the interval between months
$sp->Process();

或者

// Charge the credit card '462834666666' '$123' US dollars every week for 6 weeks starting on 01/01/10
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
$sp->SetupRepeat(SECUREPAY_REPEAT_WEEKLY, 6);
$sp->RepeatStart = strtotime('01/01/10');
$sp->Process();

或者

// Charge the credit card '462834666666' '$123' US dollars every two days for 60 days starting on 01/01/10
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
$sp->Repeat = SECUREPAY_REPEAT_DAILY;
$sp->RepeatInterval = 2;
$sp->RepeatCount = 60;
$sp->RepeatStart = strtotime('01/01/10');
$sp->Process();

设置带有手动触发器的重复支付

// Charge the credit card '462834666666' '$123' US dollars every week for 6 weeks starting on 01/01/10
// Then manually trigger the response
$sp->Cc = 462834666666;
$sp->ExpiryDate = '07/09';
$sp->ChargeAmount = 123;
$sp->ChargeCurrency = 'USD';
$sp->Cvv = 321;
$sp->OrderId = 'ORD34234';
$sp->SetupRepeat(SECUREPAY_REPEAT_WEEKLY, 6);
$sp->RepeatStart = strtotime('01/01/10');
$sp->RepeatTrigger = FALSE;
$sp->Process();
// ... The repeat payment is now setup
$sp->Trigger(); // Now start it

退款交易

//We are assuming that we have previously charged a credit card with the OrderId `ABC123` and the TransactionId was `123456`
$sp->TransactionId = 123456;
$sp->ChargeAmount = 123; //Must be less or equal to the transaction amount
$sp->OrderId = 'ABC123'; //Must be the same as the original transaction

$sp->Refund(); //Refund it!

检索所有客户信息

$sp->WebLogin('username','admin','password'); // Web login details
$details = $sp->GetClientInfo();

检索特定客户信息

$sp->WebLogin('username','admin','password'); // Web login details
$details = $sp->GetClientInfo('a_client_id');

检索今天的事务列表

$sp->WebLogin('username','admin','password');
print_r($sp->GetTransactions());

或者昨天

print_r($sp->GetTransactions('yesterday'));

或者任何日期范围

$sp->WebLogin('username','admin','password');
print_r($sp->GetTransactions(strtotime('1/1/2008'), strtotime('30/1/2008'))); // Retrieves all transactions between 1/1/2008 and 30/1/2008

谢谢

感谢Chris Bosdriesz指出,某些卡片的CVV是可选的。