Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Enrich customer creation samples #676

Open
rgy-stripe opened this issue Jan 26, 2023 · 1 comment
Open

[feature request] Enrich customer creation samples #676

rgy-stripe opened this issue Jan 26, 2023 · 1 comment

Comments

@rgy-stripe
Copy link

Bug report Feature request

The sample app uses the minimal fields for creating a customer record:

@app.route('/create-customer', methods=['POST'])
def create_customer():
    # Reads application/json and returns a response
    data = json.loads(request.data)
    try:
        # Create a new customer object
        customer = stripe.Customer.create(email=data['email'])

        # At this point, associate the ID of the Customer object with your
        # own internal representation of a customer, if you have one.
        resp = jsonify(customer=customer)

        # We're simulating authentication here by storing the ID of the customer
        # in a cookie.
        resp.set_cookie('customer', customer.id)

        return resp
    except Exception as e:
        return jsonify(error=str(e)), 403

The guide uses richer, more detailed examples for the customer records:

# Set your secret key. Remember to switch to your live secret key in production.
# See your keys here: https://dashboard.stripe.com/apikeys
import stripe
stripe.api_key = "sk_test_51MTwG0Fe8VbCz0t5SXlmkvi6ymOeib8OC0M4VHIxRS5rXjqVaDtDOHJnmK6TPPqbc9tTZBZfHT21UHlLAOV4W4RT004JYwc5pC"

stripe.Customer.create(
  email="{{CUSTOMER_EMAIL}}",
  name="{{CUSTOMER_NAME}}",
  shipping={
    "address": {
      "city": "Brothers",
      "country": "US",
      "line1": "27 Fredrick Ave",
      "postal_code": "97712",
      "state": "CA",
    },
    "name": "{{CUSTOMER_NAME}}",
  },
  address={
    "city": "Brothers",
    "country": "US",
    "line1": "27 Fredrick Ave",
    "postal_code": "97712",
    "state": "CA",
  },
)

Ideally, the two would match to make it easier for a developer to switch between them. Using more complicated, realistic data is also closer to the real-world experience of the user.

Additional context

@hideokamoto-stripe
Copy link
Contributor

Thank you for your feedback. @rgy-stripe
As a method to aim for more specific examples while reducing the complexity of implementation, what do you think about adding an AddressElement, for instance?
https://docs.stripe.com/elements/address-element

In this case, instead of using the customer.create API, information is updated during the Payment Intent's confirm process, which is slightly different from the proposed workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants