thephpleague / omnipay-pin

Pin Payments driver for the Omnipay PHP payment processing library
MIT License
12 stars 14 forks source link

Should be able to createCustomer or purchase with a card token but no card #6

Closed delatbabel closed 8 years ago

delatbabel commented 9 years ago

The API should allow purchase or createCustomer requests with no credit card, instread using a credit card token. The Pin API allows for this but the CreateCustomerRequest and PurchaseRequest classes assume a card is present because they try to obtain the email address from the card. It should be a simple matter to allow the classes to accept an email address as a separate parameter, along with a card token.

I will submit a PR for this once the PR for adding class documentation is merged (otherwise there would be conflicting changes).

sentience commented 9 years ago

Had a hard time working around this, since the actual API for passing a card token to purchase doesn’t match the documentation at all:

Here’s my working implementation (note the fake CreditCard that’s required):

$gateway = Omnipay\Omnipay::create('Pin');
$gateway->initialize([
  'secretKey'   => PIN_SECRET_KEY,
  'testMode'    => PIN_TEST_MODE
]);
$card = new Omnipay\Common\CreditCard([
  // Only value used is email - see https://github.com/thephpleague/omnipay-pin/issues/6
  'email'       => CUSTOMER_EMAIL,
  'number'      => '4200 0000 0000 0000',
  'expiryMonth' => '01',
  'expiryYear'  => '2099'
]);
$response = $gateway->purchase([
  'card'        => $card,
  'email'       => CUSTOMER_EMAIL,
  'description' => PRODUCT_DESCRIPTION,
  'amount'      => PRODUCT_PRICE,
  'currency'    => 'AUD',
  'token'       => $_REQUEST['card_token'],
  'ip_address'  => $_SERVER['REMOTE_ADDR']
])->send();
qsun commented 8 years ago

Thanks @sentience

It also works like this

        $request->setToken($token);