Comments (2)
I haven't forgotten about this but I haven't had time to look at it yet either. I will hopefully get to this next week. IIRC it was deliberate that attempting to create a card without a customer attached returned the customer token not the card token. This is for a couple of reasons:
- Historically the original version of this gateway did not implement createCustomer, only createCard. In fact it just created a customer with a single card token and returned the customer token.
- With Stripe it's possible to pay using only a customer token and no card token provided that that customer has one and only one card registered (or a default card). I think that at the time it wasn't possible to pay using just a card token without also providing the customer token.
I know that I've had several goes at ensuring that this works correctly, and as transparently as possible, even though the various methods may not always return what you expect (i.e. may return a customer token when you may expect a card token, etc).
from omnipay-stripe.
This is what works for me and I believe to be the correct flow:
$response = $gateway->createCustomer(array(
'description' => 'Test Customer',
'email' => '[email protected]',
))->send();
if ($response->isSuccessful()) {
echo "Gateway createCustomer was successful.\n";
// Find the card ID
echo "\nfetch customer ID\n=================\n";
$customer_id = $response->getCustomerReference();
echo "Customer ID = " . $customer_id . "\n";
} else {
echo "Gateway createCustomer failed.\n";
echo "Error message == " . $response->getMessage() . "\n";
}
The createCard request now follows the above call. You do not need to call updateCustomer() to add a card to a customer, instead you should use createCard()
Note that this is just a cut and paste from the code in the CreateCardRequest class docblock, it's all documented there.
$new_card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'Customer',
'number' => '5555555555554444',
'expiryMonth' => '01',
'expiryYear' => '2020',
'cvv' => '456',
'email' => '[email protected]',
'billingAddress1' => '1 Lower Creek Road',
'billingCountry' => 'AU',
'billingCity' => 'Upper Swan',
'billingPostcode' => '6999',
'billingState' => 'WA',
));
// Do a create card transaction on the gateway
$response = $gateway->createCard(array(
'card' => $new_card,
'customerReference' => $customer_id,
))->send();
if ($response->isSuccessful()) {
echo "Gateway createCard was successful.\n";
// Find the card ID
$card_id = $response->getCardReference();
echo "Card ID = " . $card_id . "\n";
}
from omnipay-stripe.
Related Issues (20)
- Redirect to checkout HOT 1
- Unable to send Stripe request HOT 1
- PHP 8 support ? HOT 1
- SetupIntents - release?
- undefined method getPaymentIntentReference() HOT 2
- Stripe not Receiving Customer Info HOT 3
- get POST data on isRedirect() HOT 1
- ListPaymentIntentsRequest
- `transactionFee` parameter does nothing
- Refund API method not implemented at all when using SCA
- New work not tagged or documented?
- Clarify when to use purchase/authorize/capture and confirm in README
- No release since fix was merged HOT 2
- Checkout gateway purchase request issues
- As per Indian regulations, export transactions require a customer name and address.
- can't use it with klarna or sofort HOT 1
- How to add local stripe other payment method ? HOT 1
- Stripe Payment Intents are not working. HOT 3
- Stripe confirming 3Ds PaymentIntent (with a failed authorization) gives wrong error HOT 1
- CreatePaymentMethodRequest - should billing details be attached to having a card?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from omnipay-stripe.