Skip to content

Commit

Permalink
merge upstream into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtweber committed Nov 9, 2015
2 parents 31846c0 + 72fe306 commit 0381651
Show file tree
Hide file tree
Showing 31 changed files with 1,166 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ If you are having general issues with Omnipay, we suggest posting on
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project,
If you want to keep up to date with release announcements, discuss ideas for the project,
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
you can subscribe to.

Expand Down
25 changes: 25 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

#
# Command line runner for unit tests for composer projects
# (c) Del 2015 http://www.babel.com.au/
# No Rights Reserved
#

#
# Clean up after any previous test runs
#
mkdir -p documents
rm -rf documents/coverage-html-new
rm -f documents/coverage.xml

#
# Run phpunit
#
vendor/bin/phpunit --coverage-html documents/coverage-html-new --coverage-clover documents/coverage.xml

if [ -d documents/coverage-html-new ]; then
rm -rf documents/coverage-html
mv documents/coverage-html-new documents/coverage-html
fi

225 changes: 225 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,75 @@ public function getName()
return 'Stripe';
}

/**
* Get the gateway parameters
*
* @return array
*/
public function getDefaultParameters()
{
return array(
'apiKey' => '',
);
}

/**
* Get the gateway API Key
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* @return string
*/
public function getApiKey()
{
return $this->getParameter('apiKey');
}

/**
* Set the gateway API Key
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* Stripe accounts have test-mode API keys as well as live-mode
* API keys. These keys can be active at the same time. Data
* created with test-mode credentials will never hit the credit
* card networks and will never cost anyone money.
*
* Unlike some gateways, there is no test mode endpoint separate
* to the live mode endpoint, the Stripe API endpoint is the same
* for test and for live.
*
* Setting the testMode flag on this gateway has no effect. To
* use test mode just use your test mode API key.
*
* @param string $value
* @return Gateway provides a fluent interface.
*/
public function setApiKey($value)
{
return $this->setParameter('apiKey', $value);
}

/**
* Authorize Request
*
* An Authorize request is similar to a purchase request but the
* charge issues an authorization (or pre-authorization), and no money
* is transferred. The transaction will need to be captured later
* in order to effect payment. Uncaptured charges expire in 7 days.
*
* Either a customerReference or a card is required. If a customerReference
* is passed in then the cardReference must be the reference of a card
* assigned to the customer. Otherwise, if you do not pass a customer ID,
* the card you provide must either be a token, like the ones returned by
* Stripe.js, or a dictionary containing a user's credit card details.
*
* IN OTHER WORDS: You cannot just pass a card reference into this request,
* you must also provide a customer reference if you want to use a stored
* card.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\AuthorizeRequest
*/
Expand All @@ -115,6 +166,10 @@ public function authorize(array $parameters = array())
}

/**
* Capture Request
*
* Use this request to capture and process a previously created authorization.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CaptureRequest
*/
Expand All @@ -124,6 +179,23 @@ public function capture(array $parameters = array())
}

/**
* Purchase request.
*
* To charge a credit card, you create a new charge object. If your API key
* is in test mode, the supplied card won't actually be charged, though
* everything else will occur as if in live mode. (Stripe assumes that the
* charge would have completed successfully).
*
* Either a customerReference or a card is required. If a customerReference
* is passed in then the cardReference must be the reference of a card
* assigned to the customer. Otherwise, if you do not pass a customer ID,
* the card you provide must either be a token, like the ones returned by
* Stripe.js, or a dictionary containing a user's credit card details.
*
* IN OTHER WORDS: You cannot just pass a card reference into this request,
* you must also provide a customer reference if you want to use a stored
* card.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\PurchaseRequest
*/
Expand All @@ -133,6 +205,17 @@ public function purchase(array $parameters = array())
}

/**
* Refund Request
*
* When you create a new refund, you must specify a
* charge to create it on.
*
* Creating a new refund will refund a charge that has
* previously been created but not yet refunded. Funds will
* be refunded to the credit or debit card that was originally
* charged. The fees you were originally charged are also
* refunded.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\RefundRequest
*/
Expand All @@ -142,6 +225,8 @@ public function refund(array $parameters = array())
}

/**
* Fetch Transaction Request
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\VoidRequest
*/
Expand All @@ -159,7 +244,21 @@ public function fetchTransaction(array $parameters = array())
return $this->createRequest('\Omnipay\Stripe\Message\FetchTransactionRequest', $parameters);
}

//
// Cards
// @link https://stripe.com/docs/api#cards
//

/**
* Create Card
*
* This call can be used to create a new customer or add a card
* to an existing customer. If a customerReference is passed in then
* a card is added to an existing customer. If there is no
* customerReference passed in then a new customer is created. The
* response in that case will then contain both a customer token
* and a card token, and is essentially the same as CreateCustomerRequest
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateCardRequest
*/
Expand All @@ -169,6 +268,19 @@ public function createCard(array $parameters = array())
}

/**
* Update Card
*
* If you need to update only some card details, like the billing
* address or expiration date, you can do so without having to re-enter
* the full card details. Stripe also works directly with card networks
* so that your customers can continue using your service without
* interruption.
*
* When you update a card, Stripe will automatically validate the card.
*
* This requires both a customerReference and a cardReference.
*
* @link https://stripe.com/docs/api#update_card
* @param array $parameters
* @return \Omnipay\Stripe\Message\UpdateCardRequest
*/
Expand All @@ -178,6 +290,29 @@ public function updateCard(array $parameters = array())
}

/**
* Delete a card.
*
* This is normally used to delete a credit card from an existing
* customer.
*
* You can delete cards from a customer or recipient. If you delete a
* card that is currently the default card on a customer or recipient,
* the most recently added card will be used as the new default. If you
* delete the last remaining card on a customer or recipient, the
* default_card attribute on the card's owner will become null.
*
* Note that for cards belonging to customers, you may want to prevent
* customers on paid subscriptions from deleting all cards on file so
* that there is at least one default card for the next invoice payment
* attempt.
*
* In deference to the previous incarnation of this gateway, where
* all CreateCard requests added a new customer and the customer ID
* was used as the card ID, if a cardReference is passed in but no
* customerReference then we assume that the cardReference is in fact
* a customerReference and delete the customer. This might be
* dangerous but it's the best way to ensure backwards compatibility.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\DeleteCardRequest
*/
Expand All @@ -186,7 +321,97 @@ public function deleteCard(array $parameters = array())
return $this->createRequest('\Omnipay\Stripe\Message\DeleteCardRequest', $parameters);
}

//
// Customers
// link: https://stripe.com/docs/api#customers
//

/**
* Create Customer
*
* Customer objects allow you to perform recurring charges and
* track multiple charges that are associated with the same customer.
* The API allows you to create, delete, and update your customers.
* You can retrieve individual customers as well as a list of all of
* your customers.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateCustomerRequest
*/
public function createCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CreateCustomerRequest', $parameters);
}

/**
* Update Customer
*
* This request updates the specified customer by setting the values
* of the parameters passed. Any parameters not provided will be left
* unchanged. For example, if you pass the card parameter, that becomes
* the customer's active card to be used for all charges in the future,
* and the customer email address is updated to the email address
* on the card. When you update a customer to a new valid card: for
* each of the customer's current subscriptions, if the subscription
* is in the `past_due` state, then the latest unpaid, unclosed
* invoice for the subscription will be retried (note that this retry
* will not count as an automatic retry, and will not affect the next
* regularly scheduled payment for the invoice). (Note also that no
* invoices pertaining to subscriptions in the `unpaid` state, or
* invoices pertaining to canceled subscriptions, will be retried as
* a result of updating the customer's card.)
*
* This request accepts mostly the same arguments as the customer
* creation call.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\CreateCustomerRequest
*/
public function updateCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\UpdateCustomerRequest', $parameters);
}

/**
* Delete a customer.
*
* Permanently deletes a customer. It cannot be undone. Also immediately
* cancels any active subscriptions on the customer.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\DeleteCustomerRequest
*/
public function deleteCustomer(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\DeleteCustomerRequest', $parameters);
}

//
// Tokens
// @link https://stripe.com/docs/api#tokens
//
// This gateway does not currently have a CreateToken message. In
// any case tokens are probably not what you are looking for because
// they are single use. You probably want to create a Customer or
// Card reference instead. This function is left here for further
// expansion.
//

/**
* Stripe Fetch Token Request
*
* Often you want to be able to charge credit cards or send payments
* to bank accounts without having to hold sensitive card information
* on your own servers. Stripe.js makes this easy in the browser, but
* you can use the same technique in other environments with our token API.
*
* Tokens can be created with your publishable API key, which can safely
* be embedded in downloadable applications like iPhone and Android apps.
* You can then use a token anywhere in our API that a card or bank account
* is accepted. Note that tokens are not meant to be stored or used more
* than once—to store these details for use later, you should create
* Customer or Recipient objects.
*
* @param array $parameters
* @return \Omnipay\Stripe\Message\FetchTokenRequest
*/
Expand Down
Loading

0 comments on commit 0381651

Please sign in to comment.