pelvo / php-pelvo
Pelvo 插件,用于集成瑞典的 Pelvo
dev-production
2022-10-07 13:02 UTC
Requires
- php: >=8.0.2
This package is auto-updated.
Last update: 2024-09-07 17:12:17 UTC
README
在这里,我们将解释我们认为对所有人来说都是难题的所有内容。
设置环境
您需要设置两个用于身份验证的环境变量
PELVO_CLIENT_ID = xxxxxxxxxxxxxxxxx
PELVO_CLIENT_SECRET = xxxxxxxxxxxxxxxxx
这些值可以从 Pelvo Dashbord 中获取。
使用 SDK
可以使用以下方式使用或导入 Pelvo SDK 到您的代码中
use Pelvo\Pelvo;
此语法可能因框架而异。
开放银行
1) 获取提供者
此函数用于获取所有提供者(通常为 TTPs)的列表,Pelvo 正在提供或在不久的将来计划提供。
$providers = Pelvo::getProviders();
这将给出以下成功的 JSON 响应
{
"providers": [
{
"provider_code": "klarna",
"flag": "klarna-logo.png",
"name": "Klarna"
},
{
"provider_code": "yapily",
"flag": "yapily-logo.svg",
"name": "Yapily"
},
{
"provider_code": "ping_payment",
"flag": "ping-payment-logo.png",
"name": "Ping Payment"
}
]
}
2) 获取机构
此函数用于获取特定提供者下所有机构(通常为银行)的列表。
$providerCode = "yapily"; // Retrieved in the previous call
$institutions = Pelvo::getInstitutions($providerCode);
这将给出以下成功的 JSON 响应,此响应可能因所选提供者而异。
{
"institutions": [
{
"id": "aibgb-sandbox",
"name": "AIB Sandbox",
"fullName": "AIB Sandbox",
"countries": [
{
"displayName": "United Kingdom",
"countryCode2": "GB"
}
],
"environmentType": "SANDBOX",
"credentialsType": "OPEN_BANKING_UK_MANUAL",
"media": [
{
"source": "https://images.yapily.com/image/802c775a-2818-483f-a81e-8b55dea90043?size=0",
"type": "logo"
},
{
"source": "https://images.yapily.com/image/0896d227-7a3a-423c-988e-000c0af04dc1?size=0",
"type": "icon"
}
],
"features": [
"INITIATE_ACCOUNT_REQUEST",
"INITIATE_DOMESTIC_SINGLE_PAYMENT",
"ACCOUNT_TRANSACTIONS_WITH_MERCHANT",
"CREATE_INTERNATIONAL_SINGLE_PAYMENT",
...
]
}
]
}
3) 授权机构
此函数用于开始所选机构的授权过程。
$providerCode = "yapily"; // Retrieved in the first call
$institutionCode = "aibgb-sandbox"; // Retrieved in the second call
$callback = "https://:8000"; // URL where system will return on institution response
$response = Pelvo::authorizeInstitution($providerCode, $institutionCode, $callback);
这将给出以下成功的 JSON 响应
{
"response": {
"error": false,
"url": "https://ob19-auth1-ui.o3bank.co.uk/....."
}
}
在浏览器中打开响应中提供的 URL 并授权同意,授权成功后,系统将返回到您提供的 URL 并带有必要参数,如下示例响应
{
"flow": "2y10ylHocz62ZWnfpu6URRUWuQAnPfOxpdsFaLgoZcAT6OXceVUr9bC",
"consent": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJJTlNUSVRVVElPTiI6Im1vZGVsby....."
}
4) 获取账户列表
此函数用于获取所选机构的账户列表。
$providerCode = "yapily"; // Retrieved in the first call
$flow = "xxxx" // Retrieved in the third call
$consent = "xxxx"; // Retrieved in the third call
$response = Pelvo::getAccounts( $providerCode, $flow, $consent);
这将给出以下成功的 JSON 响应,它可能因所选机构而异
{
"data": {
"account": {
"id": "700004000000000000000005",
"type": "Business - Current",
"balance": 1017147.2,
"currency": "GBP",
"usageType": "BUSINESS",
"accountType": "CURRENT",
"nickname": "xxxx0005",
"accountNames": [
{
"name": "Octon Inc"
}
],
"accountIdentifications": [
{
"type": "SORT_CODE",
"identification": "700001"
},
{
"type": "ACCOUNT_NUMBER",
"identification": "70000005"
}
],
"accountBalances": [
{
"type": "EXPECTED",
"dateTime": "2022-09-26T06:47:07.705Z",
"balanceAmount": {
"amount": 1017147.2,
"currency": "GBP"
},
"creditLineIncluded": false,
"creditLines": []
}
]
}
}
}
5) 启动支付
此函数用于启动所选机构的支付。
$body = array(
"provider_code" => "Code of the selected provider",
"institution_code" => "Code of the selected institution",
"callback" => "Callback URL where system will return control",
"flow" => "flow code as received in authorization",
"account_holder_name" => "Sender Account holder name",
"account_number" => "Sender Account Number",
"amount" => "Total amount to send",
"currency" => "Currency of the amount",
"reference" => "Some reference",
"receiverName" => "Name of the receiver",
"receiverCountry" => "Currency of amount to be received in",
"receiverIban" => "IBAN of the receiver"
);
$response = Pelvo::initiatePayment($body);
这将给出以下成功的 JSON 响应,它可能因所选机构而异
{
"response": {
"error": false,
"url": "https://ob19-auth1-ui.o3......"
}
}
如果响应中有 URL,则表示需要再次授权,因此请打开此 URL 并按引导操作。它将返回到回调 URL 并带有参数,如下示例响应
{
"flow": "2y10ET5DBLem2Z7IwrJ68D7nZuBanOXzNDMcRLOgnDCQOHNkgJW7RkqN6",
"consent": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJJTlNUSVRVVElPTiI6Im1vZGVsby....."
}
现在再次使用最新的流程和同意代码进行支付调用,如本示例调用
$body = array(
"provider_code" => "Code of the selected provider",
"institution_code" => "Code of the selected institution",
"callback" => "Callback URL where system will return control",
"flow" => "flow code as received in authorization",
"consent" => "consent code as received in authorization",
"account_holder_name" => "Sender Account holder name",
"account_number" => "Sender Account Number",
"amount" => "Total amount to send",
"currency" => "Currency of the amount",
"reference" => "Some reference",
"receiverName" => "Name of the receiver",
"receiverCountry" => "Currency of amount to be received in",
"receiverIban" => "IBAN of the receiver"
);
$response = Pelvo::initiatePayment($body);
这将给出以下成功的 JSON 响应,它可能因所选机构而异
{
"data": {
"error": false,
"response": {
"meta": {
"tracingId": "bb71c3b4ffa5481f912fd20b6d9e11cc"
},
"data": {
"id": "pv3-804eebc6-6e15-4017-8140-1d7ede9b8388",
"institutionConsentId": "sdp-3-5f29d50a-b717-4a29-bc48-def1efa482e9",
"status": "PENDING",
"statusDetails": {
"status": "PENDING",
"statusUpdateDate": "2022-09-26T07:08:17.305Z",
"multiAuthorisationStatus": {
"status": "AWAITING_FURTHER_AUTHORIZATION",
"numberOfAuthorisationRequired": 3,
"numberOfAuthorisationReceived": 1,
"lastUpdatedDateTime": "2022-09-26T07:08:17.309Z"
},
"isoStatus": {
"code": "PDNG",
"name": "Pending"
}
},
"payer": {
"name": "Octon Inc",
"accountIdentifications": [
{
"type": "SORT_CODE",
"identification": "700001"
},
{
"type": "ACCOUNT_NUMBER",
"identification": "70000005"
}
]
},
"payeeDetails": {
"name": "No name",
"accountIdentifications": [
{
"type": "IBAN",
"identification": "DE39499999600000005111"
}
]
},
"createdAt": "2022-09-26T07:08:17.305Z",
"firstPaymentAmount": {
"amount": 0,
"currency": "GBP"
},
"firstPaymentDateTime": "2022-09-27T08:04:48.090Z",
"numberOfPayments": 3,
"frequency": {
"frequencyType": "WEEKLY",
"intervalWeek": 1,
"executionDay": 3
}
},
"statusCode": 201
}
}
}