Invalid Request Error: Could not determine which URL to request: Stripe::Customer instance has invalid ID:...
I'm trying to implement Stripe payment onto my site. My associations, creditcard belongs to a user, and a user has many credit cards. Here's my credit_card_service code:
class CreditCardService
def initialize(user_id, card)
@user = User.find(user_id)
@card = card
end
def create_credit_card
customer = Stripe::Customer.retrieve(@user.customer_id)
customer.sources.create(source: generate_token).id
end
def generate_token
Stripe::Token.create(
card: {
number: @card[:number],
exp_month: @card[:month],
exp_year: @card[:year],
cvc: @card[:cvc]
}
).id
end
end
I get this error when I want my users to save their credit cards:
Could not determine which URL to request: Stripe::Customer instance has invalid ID: nil
This line of code is the one that I think is causing problems:
customer = Stripe::Customer.retrieve(@user.customer_id)
but I don't know what the problem is. I don't understand how my Customer ID is nil. Any help will be appreciated.
ruby-on-rails stripe-payments
add a comment |
I'm trying to implement Stripe payment onto my site. My associations, creditcard belongs to a user, and a user has many credit cards. Here's my credit_card_service code:
class CreditCardService
def initialize(user_id, card)
@user = User.find(user_id)
@card = card
end
def create_credit_card
customer = Stripe::Customer.retrieve(@user.customer_id)
customer.sources.create(source: generate_token).id
end
def generate_token
Stripe::Token.create(
card: {
number: @card[:number],
exp_month: @card[:month],
exp_year: @card[:year],
cvc: @card[:cvc]
}
).id
end
end
I get this error when I want my users to save their credit cards:
Could not determine which URL to request: Stripe::Customer instance has invalid ID: nil
This line of code is the one that I think is causing problems:
customer = Stripe::Customer.retrieve(@user.customer_id)
but I don't know what the problem is. I don't understand how my Customer ID is nil. Any help will be appreciated.
ruby-on-rails stripe-payments
have you triedputs @user.customer_idbefore that line to check the value?
– Lenin Raj Rajasekaran
Nov 26 '18 at 8:02
Yeah, it's nil. #<User id: 1, email: "achie@gmail.com", created_at: "2018-11-22 06:39:54", updated_at: "2018-11-22 06:41:09", first_name: "Linda", last_name: nil, gender: nil, gender_preferences: nil, description: "City girl", photo: nil, provider: nil, uid: nil, name: nil, image: nil, customer_id: nil>
– Linda Kadz
Nov 26 '18 at 8:40
okay, set the customer_id on@userbefore callingretrieve
– Lenin Raj Rajasekaran
Nov 26 '18 at 8:41
I can do that manually, but I need a solution for the users who will be using this service. Anything?
– Linda Kadz
Nov 26 '18 at 9:22
add a comment |
I'm trying to implement Stripe payment onto my site. My associations, creditcard belongs to a user, and a user has many credit cards. Here's my credit_card_service code:
class CreditCardService
def initialize(user_id, card)
@user = User.find(user_id)
@card = card
end
def create_credit_card
customer = Stripe::Customer.retrieve(@user.customer_id)
customer.sources.create(source: generate_token).id
end
def generate_token
Stripe::Token.create(
card: {
number: @card[:number],
exp_month: @card[:month],
exp_year: @card[:year],
cvc: @card[:cvc]
}
).id
end
end
I get this error when I want my users to save their credit cards:
Could not determine which URL to request: Stripe::Customer instance has invalid ID: nil
This line of code is the one that I think is causing problems:
customer = Stripe::Customer.retrieve(@user.customer_id)
but I don't know what the problem is. I don't understand how my Customer ID is nil. Any help will be appreciated.
ruby-on-rails stripe-payments
I'm trying to implement Stripe payment onto my site. My associations, creditcard belongs to a user, and a user has many credit cards. Here's my credit_card_service code:
class CreditCardService
def initialize(user_id, card)
@user = User.find(user_id)
@card = card
end
def create_credit_card
customer = Stripe::Customer.retrieve(@user.customer_id)
customer.sources.create(source: generate_token).id
end
def generate_token
Stripe::Token.create(
card: {
number: @card[:number],
exp_month: @card[:month],
exp_year: @card[:year],
cvc: @card[:cvc]
}
).id
end
end
I get this error when I want my users to save their credit cards:
Could not determine which URL to request: Stripe::Customer instance has invalid ID: nil
This line of code is the one that I think is causing problems:
customer = Stripe::Customer.retrieve(@user.customer_id)
but I don't know what the problem is. I don't understand how my Customer ID is nil. Any help will be appreciated.
ruby-on-rails stripe-payments
ruby-on-rails stripe-payments
edited Nov 26 '18 at 7:55
sawa
133k29206308
133k29206308
asked Nov 26 '18 at 7:36
Linda KadzLinda Kadz
196
196
have you triedputs @user.customer_idbefore that line to check the value?
– Lenin Raj Rajasekaran
Nov 26 '18 at 8:02
Yeah, it's nil. #<User id: 1, email: "achie@gmail.com", created_at: "2018-11-22 06:39:54", updated_at: "2018-11-22 06:41:09", first_name: "Linda", last_name: nil, gender: nil, gender_preferences: nil, description: "City girl", photo: nil, provider: nil, uid: nil, name: nil, image: nil, customer_id: nil>
– Linda Kadz
Nov 26 '18 at 8:40
okay, set the customer_id on@userbefore callingretrieve
– Lenin Raj Rajasekaran
Nov 26 '18 at 8:41
I can do that manually, but I need a solution for the users who will be using this service. Anything?
– Linda Kadz
Nov 26 '18 at 9:22
add a comment |
have you triedputs @user.customer_idbefore that line to check the value?
– Lenin Raj Rajasekaran
Nov 26 '18 at 8:02
Yeah, it's nil. #<User id: 1, email: "achie@gmail.com", created_at: "2018-11-22 06:39:54", updated_at: "2018-11-22 06:41:09", first_name: "Linda", last_name: nil, gender: nil, gender_preferences: nil, description: "City girl", photo: nil, provider: nil, uid: nil, name: nil, image: nil, customer_id: nil>
– Linda Kadz
Nov 26 '18 at 8:40
okay, set the customer_id on@userbefore callingretrieve
– Lenin Raj Rajasekaran
Nov 26 '18 at 8:41
I can do that manually, but I need a solution for the users who will be using this service. Anything?
– Linda Kadz
Nov 26 '18 at 9:22
have you tried
puts @user.customer_id before that line to check the value?– Lenin Raj Rajasekaran
Nov 26 '18 at 8:02
have you tried
puts @user.customer_id before that line to check the value?– Lenin Raj Rajasekaran
Nov 26 '18 at 8:02
Yeah, it's nil. #<User id: 1, email: "achie@gmail.com", created_at: "2018-11-22 06:39:54", updated_at: "2018-11-22 06:41:09", first_name: "Linda", last_name: nil, gender: nil, gender_preferences: nil, description: "City girl", photo: nil, provider: nil, uid: nil, name: nil, image: nil, customer_id: nil>
– Linda Kadz
Nov 26 '18 at 8:40
Yeah, it's nil. #<User id: 1, email: "achie@gmail.com", created_at: "2018-11-22 06:39:54", updated_at: "2018-11-22 06:41:09", first_name: "Linda", last_name: nil, gender: nil, gender_preferences: nil, description: "City girl", photo: nil, provider: nil, uid: nil, name: nil, image: nil, customer_id: nil>
– Linda Kadz
Nov 26 '18 at 8:40
okay, set the customer_id on
@user before calling retrieve– Lenin Raj Rajasekaran
Nov 26 '18 at 8:41
okay, set the customer_id on
@user before calling retrieve– Lenin Raj Rajasekaran
Nov 26 '18 at 8:41
I can do that manually, but I need a solution for the users who will be using this service. Anything?
– Linda Kadz
Nov 26 '18 at 9:22
I can do that manually, but I need a solution for the users who will be using this service. Anything?
– Linda Kadz
Nov 26 '18 at 9:22
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476549%2finvalid-request-error-could-not-determine-which-url-to-request-stripecustome%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476549%2finvalid-request-error-could-not-determine-which-url-to-request-stripecustome%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
have you tried
puts @user.customer_idbefore that line to check the value?– Lenin Raj Rajasekaran
Nov 26 '18 at 8:02
Yeah, it's nil. #<User id: 1, email: "achie@gmail.com", created_at: "2018-11-22 06:39:54", updated_at: "2018-11-22 06:41:09", first_name: "Linda", last_name: nil, gender: nil, gender_preferences: nil, description: "City girl", photo: nil, provider: nil, uid: nil, name: nil, image: nil, customer_id: nil>
– Linda Kadz
Nov 26 '18 at 8:40
okay, set the customer_id on
@userbefore callingretrieve– Lenin Raj Rajasekaran
Nov 26 '18 at 8:41
I can do that manually, but I need a solution for the users who will be using this service. Anything?
– Linda Kadz
Nov 26 '18 at 9:22