コード例 #1
0
def subscribe():
    billing_agreement = BillingAgreement({
        "name":
        "Organization plan name",
        "description":
        "Agreement for <Monthly Plan>",
        "start_date":
        (datetime.now() + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ'),
        "plan": {
            "id": "P-3NF352338H658800LZS4KMVY"
        },
        "payer": {
            "payment_method": "paypal"
        },
        "shipping_address": {
            "line1": "StayBr111idge Suites",
            "line2": "Cro12ok Street",
            "city": "San Jose",
            "state": "CA",
            "postal_code": "95112",
            "country_code": "US"
        }
    })
    if billing_agreement.create():
        for link in billing_agreement.links:
            if link.rel == "approval_url":
                approval_url = link.href
                return approval_url
    else:
        return billing_agreement.error
コード例 #2
0
ファイル: app.py プロジェクト: duquet/rest-api-sdk-python
def subscribe():
    """Customer subscribes to a billing plan to form a billing agreement
    """
    if session.get('logged_in') and session.get('customer'):
        billing_agreement = BillingAgreement({
            "name": "Organization plan name",
            "description": "Agreement for " + request.args.get('name', ''),
            "start_date": "2015-02-19T00:37:04Z",
            "plan": {
                "id": request.args.get('id', '')
            },
            "payer": {
                "payment_method": "paypal"
            },
            "shipping_address": {
                "line1": "StayBr111idge Suites",
                "line2": "Cro12ok Street",
                "city": "San Jose",
                "state": "CA",
                "postal_code": "95112",
                "country_code": "US"
            }
        })
        if billing_agreement.create():
            for link in billing_agreement.links:
                if link.rel == "approval_url":
                    approval_url = link.href
                    return redirect(approval_url)
        else:
            print(billing_agreement.error)
        return redirect(url_for('subscriptions'))
    else:
        return redirect(url_for('login'))
コード例 #3
0
	def create_billing_agreement(self, billing_plan_id):
		delay = timedelta(days=2)
		#delay = timedelta(hours=1)
		agreement = {
			"name": "Agreement for Basic Plan subscription",
			"description": "Agreement for Basic Plan subscription",
			"start_date": (datetime.now()+delay).strftime('%Y-%m-%dT%H:%M:%SZ'),
			"plan": {
				"id": billing_plan_id
			},
			"payer": {
				"payment_method": "paypal"
			},
		}
		billing_agreement = BillingAgreement(agreement)
		if billing_agreement.create():
			print("Billing Agreement creation successful! {}".format(billing_agreement.id))
			print(billing_agreement)
			for link in billing_agreement.links:
				print(link.rel)
				print(link.href)
				if link.rel == "approval_url":
					approval_url = link.href
					print(approval_url)
		else:
			print("Billing Agreement creation failed! {}".format(billing_agreement.error))
		return billing_agreement
コード例 #4
0
ファイル: __init__.py プロジェクト: heynemann/flask-paypal
def plan_payment_url(value):
    plan_details = current_app.paypal['plans'][value]

    billing_agreement = BillingAgreement({
        "name":
        g.user.name,
        "description":
        "Agreement for %s" % plan_details['name'],
        "start_date": (datetime.utcnow() +
                       timedelta(minutes=1)).strftime("%Y-%m-%dT%H:%M:%SZ"),
        "plan": {
            "id": plan_details.id
        },
        "payer": {
            "payment_method": "paypal"
        },
    })
    import ipdb
    ipdb.set_trace()  # XXX BREAKPOINT
    if billing_agreement.create():
        for link in billing_agreement.links:
            if link.rel == "approval_url":
                approval_url = link.href

                return approval_url

    raise RuntimeError('Could not get approval url for plan %s.' %
                       plan_details.name)
コード例 #5
0
def subscribe():
    """Customer subscribes to a billing plan to form a billing agreement
    """
    if session.get('logged_in') and session.get('customer'):
        billing_agreement = BillingAgreement({
            "name": "Organization plan name",
            "description": "Agreement for " + request.args.get('name', ''),
            "start_date": "2015-02-19T00:37:04Z",
            "plan": {
                "id": request.args.get('id', '')
            },
            "payer": {
                "payment_method": "paypal"
            },
            "shipping_address": {
                "line1": "StayBr111idge Suites",
                "line2": "Cro12ok Street",
                "city": "San Jose",
                "state": "CA",
                "postal_code": "95112",
                "country_code": "US"
            }
        })
        if billing_agreement.create():
            for link in billing_agreement.links:
                if link.rel == "approval_url":
                    approval_url = link.href
                    return redirect(approval_url)
        else:
            print(billing_agreement.error)
        return redirect(url_for('subscriptions'))
    else:
        return redirect(url_for('login'))
コード例 #6
0
    def post(self):
        data = json.loads(self.request.body.decode('utf-8'))
        billing_agreement = BillingAgreement({
            "name":
            "Organization plan name",
            "description":
            "Agreement for " + data['name'],
            "start_date":
            (datetime.datetime.now() +
             datetime.timedelta(days=365)).strftime('%Y-%m-%dT%H:%M:%SZ'),
            "plan": {
                "id": data['id']
            },
            "payer": {
                "payment_method": "paypal"
            },
            "shipping_address": {
                "line1": "StayBr111idge Suites",
                "line2": "Cro12ok Street",
                "city": "San Jose",
                "state": "CA",
                "postal_code": "95112",
                "country_code": "US"
            }
        })
        if billing_agreement.create():
            for link in billing_agreement.links:
                if link.rel == "approval_url":
                    approval_url = link.href
                    msg = approval_url
        else:
            msg = billing_agreement.error
            print(msg)

        self.write({'response': msg})
コード例 #7
0
    def get(self):
        from flask import request
        from datetime import datetime
        from paypalrestsdk import BillingAgreement
        from app import app
        from flask import redirect

        now = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')

        billing_agreement = None

        if request.args.get('sub') == 'pro':
            billing_agreement = BillingAgreement({
                "name": "Pro Agreement",
                "description": "- up to 5 updates get saved;\n-Play store researches;\n-News researches;",
                "start_date": now,
                "plan": {
                    "id": app.config['PRO']
                },
                "payer": {
                    "payment_method": "paypal"
                }
            })
        
        else:
            billing_agreement = BillingAgreement({
                "name": "Premium Agreement",
                "description": "- unlimited updates;\n- all the modules;",
                "start_date": now,
                "plan": {
                    "id": app.config['PREMIUM']
                },
                "payer": {
                    "payment_method": "paypal"
                }
            })

        if billing_agreement.create():
            print(billing_agreement.links)
            for link in billing_agreement.links:
                if link.method == "REDIRECT":
                    redirect_url = str(link.href)

                    return redirect(redirect_url)
        else:
            print(billing_agreement.error)
コード例 #8
0
ファイル: __init__.py プロジェクト: heynemann/flask-paypal
def plan_payment_url(value):
    plan_details = current_app.paypal['plans'][value]

    billing_agreement = BillingAgreement({
        "name": g.user.name,
        "description": "Agreement for %s" % plan_details['name'],
        "start_date": (datetime.utcnow() + timedelta(minutes=1)).strftime("%Y-%m-%dT%H:%M:%SZ"),
        "plan": {
            "id": plan_details.id
        },
        "payer": {
            "payment_method": "paypal"
        },
    })
    import ipdb; ipdb.set_trace()  # XXX BREAKPOINT
    if billing_agreement.create():
        for link in billing_agreement.links:
            if link.rel == "approval_url":
                approval_url = link.href

                return approval_url

    raise RuntimeError('Could not get approval url for plan %s.' % plan_details.name)
コード例 #9
0
from paypalrestsdk import BillingAgreement
import logging

logging.basicConfig(level=logging.INFO)

billing_agreement = BillingAgreement({
    "name": "Fast Speed Agreement",
    "description": "Agreement for Fast Speed Plan",
    "start_date": "2015-02-19T00:37:04Z",
    "plan": {
        "id": "P-0NJ10521L3680291SOAQIVTQ"
    },
    "payer": {
        "payment_method": "paypal"
    },
    "shipping_address": {
        "line1": "StayBr111idge Suites",
        "line2": "Cro12ok Street",
        "city": "San Jose",
        "state": "CA",
        "postal_code": "95112",
        "country_code": "US"
    }
})

if billing_agreement.create():
    print("Billing Agreement created successfully")
else:
    print((billing_agreement.error))
コード例 #10
0
def subscribe(payment_id, user_id=None, ccform=None):
    """ Function to create billing agreement using credit card and paypal """
    try:
        configure_paypal()
        user_detail = current_user
        if user_id is not None:
            user_detail = User.by_id(user_id)
            session['app_user_id'] = user_id

        if ccform is not None:
            exp_detail = ccform.expiry_date.data.split('/')
            exp_month = exp_detail[0] if exp_detail[0] else 0
            exp_year = exp_detail[1] if exp_detail[1] else 0
            payer_info = {
                "payer": {
                    "payment_method":
                    "credit_card",
                    "funding_instruments": [{
                        "credit_card": {
                            "type": str(ccform.type.data),
                            "number": str(ccform.card_number.data),
                            "expire_month": str(exp_month),
                            "expire_year": str(exp_year),
                            "cvv2": str(ccform.cvv.data),
                            "first_name": str(ccform.first_name.data),
                            "last_name": str(ccform.last_name.data),
                            "billing_address": {
                                "line1": str(current_user.address1),
                                "line2": str(current_user.address2),
                                "city": str(current_user.city),
                                "state": str(current_user.state),
                                "postal_code": str(current_user.zipcode),
                                "country_code": "US"
                            }
                        },
                    }]
                }
            }
        else:
            payer_info = {
                "payer": {
                    "payment_method": "paypal",
                    "funding_option_id": user_detail.id,
                    "payer_info": {
                        "email": user_detail.email,
                        "first_name": user_detail.first_name,
                        "last_name": user_detail.last_name,
                    }
                }
            }
        plan = Subscription.by_planid(payment_id)
        billing_agreement = BillingAgreement({
            "name":
            plan.subscription_name,
            "description":
            "Agreement for the recurring payment for the plan " +
            plan.subscription_name + ". The cost of this plan is $" +
            str('%.2f' % plan.subscription_price) + " /month.",
            "start_date": (datetime.now() +
                           timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ'),
            "plan": {
                "id": str(payment_id)
            },
            "payer":
            payer_info['payer'],
        })
        if billing_agreement.create():
            if ccform is not None:
                billing_agreement_response = BillingAgreement.execute(
                    billing_agreement.id)
                return save_credit_card_response(billing_agreement, payment_id)
            for link in billing_agreement.links:

                if link.rel == "approval_url":
                    approval_url = link.href
                    return approval_url
            return False
        else:
            errorlog.error('Subscribe Error',
                           details=str(billing_agreement.error))
            flash(SUBSCRIPTION_ERROR, 'danger')
        return False

    except Exception as err:
        errorlog.error('Subscribe Error', details=str(err))
        flash(SUBSCRIPTION_ERROR, 'danger')
        return redirect(url_for('paymentbp.billing'))
コード例 #11
0
    "payer": {
        "payment_method": "paypal"
    },
    "shipping_address": {
        "line1": "StayBr111idge Suites",
        "line2": "Cro12ok Street",
        "city": "San Jose",
        "state": "CA",
        "postal_code": "95112",
        "country_code": "US"
    }
})

# After creating the agreement, redirect user to the url provided in links array
# entry with method field set to REDIRECT
if billing_agreement.create():
    print("Billing Agreement created successfully")
    for link in billing_agreement.links:
        if link.rel == "approval_url":
            approval_url = link.href
            print(
                "For approving billing agreement, redirect user to\n [%s]" % (approval_url))
else:
    print(billing_agreement.error)

# After user approves the agreement, call execute with the payment token appended to
# the redirect url to execute the billing agreement.
# https://github.paypal.com/pages/lkutch/paypal-developer-docs/api/#execute-an-agreement
billing_agreement_response = BillingAgreement.execute(payment_token)
print("BillingAgreement[%s] executed successfully" %
      (billing_agreement_response.id))
コード例 #12
0
        "city": "San Jose",
        "state": "CA",
        "postal_code": "95112",
        "country_code": "US"
    }
})


# Parse links and get payment token
def get_payment_token(links):
    for link in links:
        if link.rel == "approval_url":
            return parse.parse_qs(parse.urlparse(link.href).query)["token"][0]


if billing_agreement.create(None, None, True):
    result = {
        "id":
        get_payment_token(billing_agreement.links),
        "name":
        billing_agreement.name,
        "description":
        billing_agreement.description,
        "plan_state":
        billing_agreement.plan.state,
        "start_date":
        billing_agreement.start_date,
        "links": [{
            "href": link.href,
            "rel": link.rel,
            "method": link.method