使用Maypole进行快速Web应用开发:第2部分

作者:凯旋网络来源:凯旋网络
rmmethod="post"action="https://www.isellit.com/user/do_checkout"><P>Firstname:<inputname="first_name"value="[my.first_name]"><BR>Lastname:<inputname="last_name"value="[my.last_name]"></P><P>Streetaddress:<inputname="address"value="[my.address1]"><BR>City:<inputname="city"value="[my.address2]"><BR>State:<inputname="state"value="[my.state]">Zip:<inputname="zip"value="[my.postal_code]"></P><P>Cardtype:<selectname="type"><option>Visa</option><option>Mastercard</option>...</select>Cardnumber:<inputname="card_number">Expiration:<inputname="expiration"><BR>Total:$[total_price]</P><P>Pleaseclick<B>once</B>andwaitforthepaymenttobeauthorised....<inputtype="submit"value="order"></form>

当这些数据被提交给do_checkout动作时会发生什么呢?(你会注意到这是通过SSL连接的)。我们将会先检查用户是否已经输入地址详情,而且如果是的话,把它们存进数据库。也许这在浏览器能自动填写表单的今天显得没什么必要,不过仍不失为一项便利的措施。Maypole把POST过来的参数储存在params中:

subdo_checkout:Exported{my($self,$r)=@_;myparams={$r->{params}};my$user=$r->{user};$user->address1($params{address})unless$user->address1;$user->address2($params{city})unless$user->address2;$user->state($params{state})unless$user->state;$user->postal_code($params{zip})unless$user->postal_code;

我们需要借助Business::OnlinePayment构造一个发送给外部支付网关的请求;太感谢了,我们接收到的表单参数将正好是OnlinePayment需要的格式,感谢这么体贴的表单设计。所有我们需要做的就是插入我们的帐户明细和总额:

my$tx=newBusiness::OnlinePayment("TCLink");$tx->content(params,type=>"cc",login=>VENDOR_LOGIN,password=>VENDOR_PASSWORD,action=>''NormalAuthorization''amount=>$r->{user}->basket_total);

现在我们能提交账单,然后看有什么发生。如果有问题,我们会把一个消息加入模板,而且再一次把用户送回先前的页面:

$tx->submit;if(!$tx->is_success){$r->{template_args}{message}="Therewasaproblemauthorizingyourtransaction:".$tx->error_message;$r->{template}="checkout";return;}

没有问题的话,我们就能得到支付给我们的钱;现在我们得把它告诉发货员,否则我们会很快失去客户:

fulfill_order(address_details=>$r->{params},order_details=>[map{



使用Maypole进行快速Web应用开发:第2部分 - 凯旋网络










使用Maypole进行快速Web应用开发:第2部分

作者:凯旋网络来源:凯旋网络
content
  • 广告推荐
    ->item}$r->{user}->cart_items],cc_auth=>$tx->authorization);

    那么现在我们清空购物车,把用户送上路:

    
    
    
    
    使用Maypole进行快速Web应用开发:第2部分 - 凯旋网络
    
    
    
    
    
    
    
    
    
    
    

    使用Maypole进行快速Web应用开发:第2部分

    作者:凯旋网络来源:凯旋网络
    content
  • 广告推荐
    ->deletefor$r->{user}->cart_items;$r->{template}="frontpage";}

    完成!我们已带用户完成了登陆,把商品加入购物车,验证信用卡及结帐的过程。但是……稍等。起初我们怎样得到用户呢?

    注册用户

    我们必须找一个方法来让用户注册。实际上这并不怎么难,特别是因为我们能使用Maypole手册中Flox的例子。首先,我们将会把一个"注册"链接加入我们的登录模板:

    <P>Newuser?<AHREF="/user/register">Signup!</A></P>

    这页不需要载入任何对象,因为它只是用来显示一个注册表单;我们只要把我们的模板加入/user/register:

    [INCLUDEheader]<P>WelcometobuyingwithiSellIt!</P
  • 广告推荐