在直接付款授权被接受后,如何捕获由 Go Cardless 发回我的网站的 GoCardless 重定向?
How to capture a GoCardless redirect sent back by Go Cardless to my website once the direct debit mandate has been accepted?
这是我的 CustomerController,它获取要发送直接付款授权书的客户核对清单,其中包含我在数据库中已有的详细信息。一旦客户填写了授权书,Gocardless 就会将重定向 uri 发送到设置 "success_redirect_url",这是站点控制器下的操作,即。 site/gocardlesscustomercreated
public function actionCreategocardlesscustomer()
{
$keylist = Yii::$app->request->get('keylist');
$comp = Company::findOne(1);
if (!empty($keylist)){
foreach ($keylist as $key => $value)
{
$model = $this->findModel($value);
if ($model !== null)
{
$client = new \GoCardlessPro\Client([
'access_token' => 'sandbox_b__7gf_Vn6dYEKFTy3C-GMRamuFz_siKhQsMiZ-',
'environment' => \GoCardlessPro\Environment::SANDBOX
]);
$redirectFlow = $client->redirectFlows()->create([
'params' => [
"description" => "Clean",
"session_token" => Yii::$app->session->getId(),
"success_redirect_url" => Url::to(['site/gocardlesscustomercreated'], 'http'),
"prefilled_customer" => [
"given_name" => $model->name,
"family_name" => $model->surname,
"email" => $model->email,
"address_line1" => $model->productnumber." ".$model->productsubcategory->name,
"city" => $comp->address_area2,
"postal_code" => $model->postcodefirsthalf." ".$model->postcodesecondhalf,
]
]
]);
Yii::$app->session->setFlash('success', "ID: " . $redirectFlow->id ." Create Customer on Gocardless: ".Html::a($redirectFlow->redirect_url,$redirectFlow->redirect_url));
}
}
Yii::$app->session['redirectflowid'] = $redirectFlow->id;
Yii::$app->session['redirectflowredirecturl'] = $redirectFlow->redirect_url;
}
else throw new NotFoundHttpException('No ticks selected.');
}
重定向后,我在浏览器中从 Gocardless 获得的完整 Url 是:
http://frontend.dev/site/gocardlesscustomercreated?redirect_flow_id=RE0000Y6TRAAQHGHWR4C5ZTEA18S2QJG
我如何捕捉这个
?redirect_flow_id=RE0000Y6TRAAQHGHWR4C5ZTEA18S2QJG
Gocardless 已添加到我的 Url::to 并发回?
我是否在 UrlManager 下使用如下规则:
'site/gocardlesscustomercreated/<id:\d+>'=>'site/gocardlesscustomercreated'
或者我最好还是使用
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'gocardlesscustomercreated'],
],
或调整.htaccess。 ?
您需要做的就是能够传递由 gocardless 发送的参数,这样您就可以获取并使用它您不需要在 urlManager
中专门分配任何 url 规则向您的操作添加一个参数 gocardlesscustomercreated
,其名称与从 gocardless 传递的参数同名,如下所示
public function actionGocardlesscustomercreated($redirect_flow_id)
现在您可以在操作中回显 $redirect_flow_id
以打印它或将其保存在任何您喜欢的地方
这是我的 CustomerController,它获取要发送直接付款授权书的客户核对清单,其中包含我在数据库中已有的详细信息。一旦客户填写了授权书,Gocardless 就会将重定向 uri 发送到设置 "success_redirect_url",这是站点控制器下的操作,即。 site/gocardlesscustomercreated
public function actionCreategocardlesscustomer()
{
$keylist = Yii::$app->request->get('keylist');
$comp = Company::findOne(1);
if (!empty($keylist)){
foreach ($keylist as $key => $value)
{
$model = $this->findModel($value);
if ($model !== null)
{
$client = new \GoCardlessPro\Client([
'access_token' => 'sandbox_b__7gf_Vn6dYEKFTy3C-GMRamuFz_siKhQsMiZ-',
'environment' => \GoCardlessPro\Environment::SANDBOX
]);
$redirectFlow = $client->redirectFlows()->create([
'params' => [
"description" => "Clean",
"session_token" => Yii::$app->session->getId(),
"success_redirect_url" => Url::to(['site/gocardlesscustomercreated'], 'http'),
"prefilled_customer" => [
"given_name" => $model->name,
"family_name" => $model->surname,
"email" => $model->email,
"address_line1" => $model->productnumber." ".$model->productsubcategory->name,
"city" => $comp->address_area2,
"postal_code" => $model->postcodefirsthalf." ".$model->postcodesecondhalf,
]
]
]);
Yii::$app->session->setFlash('success', "ID: " . $redirectFlow->id ." Create Customer on Gocardless: ".Html::a($redirectFlow->redirect_url,$redirectFlow->redirect_url));
}
}
Yii::$app->session['redirectflowid'] = $redirectFlow->id;
Yii::$app->session['redirectflowredirecturl'] = $redirectFlow->redirect_url;
}
else throw new NotFoundHttpException('No ticks selected.');
}
重定向后,我在浏览器中从 Gocardless 获得的完整 Url 是: http://frontend.dev/site/gocardlesscustomercreated?redirect_flow_id=RE0000Y6TRAAQHGHWR4C5ZTEA18S2QJG
我如何捕捉这个
?redirect_flow_id=RE0000Y6TRAAQHGHWR4C5ZTEA18S2QJG
Gocardless 已添加到我的 Url::to 并发回?
我是否在 UrlManager 下使用如下规则:
'site/gocardlesscustomercreated/<id:\d+>'=>'site/gocardlesscustomercreated'
或者我最好还是使用
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'gocardlesscustomercreated'],
],
或调整.htaccess。 ?
您需要做的就是能够传递由 gocardless 发送的参数,这样您就可以获取并使用它您不需要在 urlManager
中专门分配任何 url 规则向您的操作添加一个参数 gocardlesscustomercreated
,其名称与从 gocardless 传递的参数同名,如下所示
public function actionGocardlesscustomercreated($redirect_flow_id)
现在您可以在操作中回显 $redirect_flow_id
以打印它或将其保存在任何您喜欢的地方