Coder Social home page Coder Social logo

Comments (2)

delatbabel avatar delatbabel commented on August 16, 2024

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.

delatbabel avatar delatbabel commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.