2

这是我的 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 在浏览器中获得的完整网址是: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。?

4

1 回答 1

1

您需要做的就是能够传递 gocardless 发送的参数,以便您可以获取并使用它您不需要专门分配任何 url 规则,urlManager只需将参数添加到gocardlesscustomercreated与传递的参数同名的操作即可从 gocardless 如下

public function actionGocardlesscustomercreated($redirect_flow_id)

现在,您可以$redirect_flow_id在操作中回显以打印或将其保存在您喜欢的任何位置

于 2018-03-29T22:18:31.663 回答