我确定我在这里遗漏了一些明显的东西,但是我无法理解如何检查现有卡片对顾客的看法.
我在laravel应用程序中使用条带连接api来代表其他人管理付款,基本过程如下:
token
通过stripe.js
付款表单创建并提交条带stripe_id
,否则使用令牌作为源/卡创建新客户charge
然后使用检索到的或新客户创建astripe_id
目前,如果客户退回并使用不同的卡,由于收费仅包括客户而非来源,因此无论如何都将对其默认卡收费.
我想做的是:
token
customer
本地数据库等card
客户卡的指纹card
在客户的记录上创建新的customer
和card
ids 创建费用简单地说:我无法看到过程card_id
中生成持久性的位置; 在stripe.js
响应中使用的那些以及在条带仪表板中创建的那些看起来都是唯一的,这意味着每次充电都会创建一个全新的卡片对象.
我知道我可以检索存储在客户帐户中的卡片列表 - 但是我card_id
从哪里获取初始搜索?
我在这里看到了一个涉及此问题的问题 - 在创建新卡片之前,我是否可以检查条带是否已经存在? - 但我不知道Ruby,所以不能做头或尾.
编辑:
更简单的版本 - 有没有办法在这里获得fingerprint
条纹文档中描述的内容 - https://stripe.com/docs/api/php#card_object - 无需先创建卡片对象?
我已经能够使用以下原始sql获取我需要的查询结果:
select `person`.`id`, `full_name`, count(actions.user_id) as total
from `persons`
left join `actions`
on `actions`.`person_id` = `persons`.`id`
and `actions`.`user_id` = $user
where `type` = 'mp'
group by `persons`.`id`
Run Code Online (Sandbox Code Playgroud)
但我还没有能够以雄辩的方式开展工作.
基于一些类似的答案,我尝试过内部->where()
或各种功能leftJoin()
,但count
每个人的行为尚未被过滤掉$user
.目前的情况:
$query = Person::leftJoin('actions', function($q) use ($user)
{
$q->on('actions.person_id', 'persons.id')
->where('actions.user_id', $user);
})
->groupBy('persons.id')
->where('type', 'foo')
//->where('actions.user_id', '=', $user)
->get(['persons.id', 'full_name', DB::raw('count(actions.id) as total')]);
Run Code Online (Sandbox Code Playgroud)
我至少在标题大致正确的方向,正确的...?
如果相关,则Persons.php
模型有两种actions
关系:
public function actions()
{
return $this->hasMany('Action');
}
public function actionsUser($id)
{
return …
Run Code Online (Sandbox Code Playgroud) 我有三个表 - 活动,行动和活动家.Campaign有许多操作,Action属于Activist和Campaign.
每个操作都有一个client_id(来自其所属广告系列的client_id),因此当客户查看活动家列表时,他们应该只看到那些对其中一个广告系列采取了操作的人.
同样,在查看个人活动家时,他们应该只看到与其广告系列相关的操作.
楷模
Campaign.php
public function actions()
{
return $this->hasMany('Action');
}
Run Code Online (Sandbox Code Playgroud)
action.php的
public function campaign()
{
return $this->belongsTo('Campaign', 'campaign_id');
}
public function activist()
{
return $this->belongsTo('Activist', 'activist_id');
}
Run Code Online (Sandbox Code Playgroud)
Activists.php
public function actions()
{
return $this->hasMany('Action');
}
Run Code Online (Sandbox Code Playgroud)
控制器
ActivistsController.php
public function index()
{
$activists = Activist::with('actions')->whereHas('actions', function($q) {
$user = Sentry::getUser();
$q->where('client_id', $user->client_id);
}))->get();
foreach ($activists as $activist)
{
$activist->total = $activist->actions()->count();
}
}
public function getActivist($id)
{
$activist = Activist::with('actions')->whereHas('actions', function($q) {
$user = Sentry::getUser();
$q->where('client_id', $user->client_id); …
Run Code Online (Sandbox Code Playgroud) 我有一个postgres数据库表,它使用uuid作为主键,通过webpatser/laravel-uuid包,通过vinkla/hashids使用 '可读'web ID .
当我查询数据库时,如果我dd()响应,我完全看到UUID,但如果我只是返回,我会得到一个整数.
假设我忽略了一些明显的东西,所以:
移民
$table->uuid('id');
$table->string('web_id');
$table->primary('id');
Run Code Online (Sandbox Code Playgroud)
模型
public function store()
{
$data = [
'id' => Uuid::generate(4)->string,
'web_id' => Hashids::encode(mt_rand(1,1000000)),
Run Code Online (Sandbox Code Playgroud)
我假设当数据被转换为json时会发生一些事情,但我不知道我会在哪里开始解决这个问题......
我也在工匠修补匠看到同样的行为,fwiw:
>>> $result = App\Model::firstOrFail()
=> App\Model {#675
id: "587bb487-881d-417e-8960-fbecaa3b270b",
web_id: "Mxqv4LYP",
created_at: "2016-01-25 15:52:25+00",
updated_at: "2016-01-25 15:52:25+00",
}
>>> $result->id
=> 587
Run Code Online (Sandbox Code Playgroud)