当前位置: 首页>>代码示例>>Python>>正文


Python Order.paypal_order_id方法代码示例

本文整理汇总了Python中models.Order.paypal_order_id方法的典型用法代码示例。如果您正苦于以下问题:Python Order.paypal_order_id方法的具体用法?Python Order.paypal_order_id怎么用?Python Order.paypal_order_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Order的用法示例。


在下文中一共展示了Order.paypal_order_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: support_post

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import paypal_order_id [as 别名]
def support_post(vanity_url):
    login_form = LoginForm()
    signup_form = SignupForm()
    campaign = Campaign.query.filter_by(vanity_url=vanity_url).one()

    checkout_form = CheckoutForm(request.form)
    current_user = (login.current_user.is_authenticated() and [login.current_user] or [None])[0]
    reward = None
    if checkout_form.reward_id.data:
        reward = Reward.query.filter_by(id=checkout_form.reward_id.data).first()

    if current_user:
        checkout_form.anon_info.form_class.is_form_optional=True

    if reward and reward.is_shipping_required:
        checkout_form.shipping_info.form_class.is_form_optional=False
    else:
        checkout_form.shipping_info.form_class.is_form_optional=True

    if not checkout_form.validate_on_submit():
        return render_template("campaign/purchase.html", model=campaign, login_form=login_form, signup_form=signup_form,form=checkout_form,current_reward=reward,user=current_user)

    if current_user == None:
        current_user = User(
            password=str(uuid.uuid4()),
            email=checkout_form.anon_info.email.data,
            user_type=UserType.Backer,
            is_anonymous=True
        )
        db.session.add(current_user)
        db.session.commit()

    total = float(reward.cost + reward.cost) if reward else float(checkout_form.contributionamount.data)
    shipping_fee = 0

    if reward and reward.is_shipping_required:
        shipping_fee = reward.shipping_fee if checkout_form.shipping_info.country == 'US' else reward.international_shipping_fee

    if(reward):
        if(float(checkout_form.contributionamount.data) > float(reward.cost + reward.cost)):
            total = float(checkout_form.contributionamount.data)
    else:
        total = float(checkout_form.contributionamount.data)

    order = Order(
        cost = reward.cost if reward else 0,
        tax = 0,
        contribution = checkout_form.contributionamount.data,
        shipping = shipping_fee,
        total = float(total),
        order_status_id = OrderStatus.Created,
        is_shipping=reward.is_shipping_required if reward else False,
        is_private=False,
        shipping_date=reward.delivery_date if reward else None,
        user_id=current_user.id,
        campaign_id=campaign.id,
        reward_id=reward.id if reward else None,
        paypal_order_id=''
    )

    if reward and reward.is_shipping_required:
        contact = ContactInfo()
        contact.address = checkout_form.shipping_info.address.data
        contact.city = checkout_form.shipping_info.city.data
        contact.state = ""#checkout_form.shipping_info.state.data
        contact.postal_code = checkout_form.shipping_info.postal_code.data
        contact.country = checkout_form.shipping_info.country.data
        order.shipping_info = contact
    db.session.add(order)
    db.session.commit()

    raw_data = campaign_service.get_draft(campaign.published_document_id)['data']

    return_url = APP_BASE_URL + url_for('.support_success',vanity_url=vanity_url)
    cancel_url = APP_BASE_URL + url_for('.support_cancel',vanity_url=vanity_url)

    payment = paypalrestsdk.Payment({
      "intent": "sale",
      "payer": {
        "payment_method": "paypal" },
      "redirect_urls": {
        "return_url": str(return_url),
        "cancel_url": str(cancel_url)
      },
      "transactions": [ {
        "amount": {
          "total": '%.2f' % order.total,
          "currency": "USD" },
        "description": str(escape(reward.title if reward else 'Fanbacked Contribution')) } ] } )


    response = payment.create()
    if response:
        payment_id = payment.id
        session['paypal_payment_id'] = payment_id
        order.paypal_order_id = payment_id
        order.order_status_id=OrderStatus.Submitted
        db.session.commit()
        for link in payment.links:
            if link.method == "REDIRECT":
#.........这里部分代码省略.........
开发者ID:Denrybin,项目名称:backcapital,代码行数:103,代码来源:views.py


注:本文中的models.Order.paypal_order_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。