Skip to content

Commit

Permalink
One small step...
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Holder-Chow Lin On committed May 30, 2014
0 parents commit de84f85
Show file tree
Hide file tree
Showing 24 changed files with 1,088 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
composer.lock
.DS_Store
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# override like so: make dependencies COMPOSER=$(which composer.phar)
COMPOSER = ./build/composer.phar

.PHONY : test
test:
php ./test/Affirm.php

.PHONY : dependencies
dependencies:
$(COMPOSER) update --dev
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[![](docs/splash.png)](https://affirm.com)

**Compatible with**

Magento CE 1.4.0.1+

Install
-------

**To install using [modgit](https://github.com/jreinke/modgit):**

```
cd MAGENTO_ROOT
modgit -i extension/:. add Magento_Affirm [email protected]:Affirm/Magento_Affirm.git
```
to update:
```
modgit update Magento_Affirm
```

**To install using [modman](https://github.com/colinmollenhour/modman):**

```
cd MAGENTO_ROOT
modman clone [email protected]:Affirm/Magento_Affirm.git
```
to update:
```
modman update Magento_Affirm
```

**To install using Affirm's deploy script:**

1. Download the [Makefile](https://gist.githubusercontent.com/perfmode/ad8cf189bbbaeeae1181/raw/6fb5e861a6dddc8cd6685573e492b0662c498a15/Makefile) (requires wget)
2. Copy to MAGENTO_ROOT
3. To install, run `make install`
4. To update, run `make update`

Configure
---------

1. Log in to your Magento Admin portal.
2. Visit System > Configuration > Payment Methods (under Sales) > Affirm
3. Set the API URL. In a test environment, use ```https://sandbox.affirm.com```. On your live site, use ```https://www.affirm.com```.
4. Provide your 3 keys (merchant API key, secret key, financial product key)
5. Adjust the order total minimum and maximum options to control when Affirm is
shown to your customers.

![](docs/config.png)


Contribute
----------

1. Fork the repo
2. Create your feature branch (```git checkout -b my-new-feature```).
3. Commit your changes (```git commit -am 'Added some feature'```)
4. Push to the branch (```git push origin my-new-feature```)
5. Create a Pull Request

**To run the tests:**

```
make dependencies
make test
```
Binary file added build/composer.phar
Binary file not shown.
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "affirm/affirm-php",
"description": "Affirm PHP bindings",
"keywords": [
"affirm",
"api",
"consumer finance",
"credit",
"e-commerce",
"payment method"
],
"homepage": "https://affirm.com/",
"authors": [
{
"name": "The Affirm Technology Team",
"homepage": "https://www.affirm.com/company"
}
],
"require": {
"php": ">=5.2"
},
"require-dev": {
"zendframework/zendframework1": "1.12.6",
"simpletest/simpletest": "1.1.*"
},
"autoload": {
"classmap": ["extension/lib/Affirm/"]
}
}
Binary file added docs/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions extension/app/code/community/Affirm/Affirm/Block/Payment/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
class Affirm_Affirm_Block_Payment_Form extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
// TODO(brian): refactor this into a 3 step process to make the state
// change more explicit
$this->replaceLabel();
}

protected function _toHtml()
{
// TODO(brian): extract this html block to a template
// TODO(brian): extract css
$msg = "You'll complete your payment after you place your order.";

$html = "<ul class=\"form-list\" id=\"payment_form_affirm\" style=\"display:none;\">";
$html .= "<li class=\"form-alt\">";

// heading
$html .= "<div style=\"color:#034082; font-size:16px; \">";
$html .= "Pay over time in 3 easy payments";
$html .= "</div>";

// sub
$html .= "<div style=\"color:#6f6f6f; font-size:14px; \">";
$html .= "just enter your basic details and get";
$html .= "<br>";
$html .= "approved instantly.";
$html .= "</div>";

$html .= "</li>";
$html .= "</ul>";

return $html;
}

/* Replaces default label with custom image, conditionally displaying text
* based on the Affirm product.
*
* Context: Payment Information step of Checkout flow
*/
private function replaceLabel()
{
$this->setMethodTitle(""); // removes default title

// TODO(brian): extract html to template
// TODO(brian): conditionally load based on env config option
// This is a stopgap until the promo API is ready to go
$logoSrc = "https://cdn1.affirm.com/images/badges/affirm-card_78x54.png";
$html = "<img src=\"" . $logoSrc . "\" width=\"39\" height=\"27\" class=\"v-middle\" />&nbsp;";

// TODO(brian): conditionally display based on payment type
// alt message: $html.= "Buy Now and Pay Later";
$html.= "3 Monthly Payments with Split Pay";

$this->setMethodLabelAfterHtml($html);
}
}
11 changes: 11 additions & 0 deletions extension/app/code/community/Affirm/Affirm/Block/Payment/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
class Affirm_Affirm_Block_Payment_Info extends Mage_Payment_Block_Info
{

protected function _toHtml()
{
$html = '<a href="https://www.affirm.com/u/">Affirm Split Pay</a>';
return $html;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
class Affirm_Affirm_Block_Payment_Redirect extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
$order = $this->getOrder();
$payment_method = $order->getPayment()->getMethodInstance();

$html = '<html><body>';
$html.= '<script type="text/javascript" src="'. trim($payment_method->getBaseApiUrl(), "/") . '/js/v2/affirm.js"></script>';
$html.= '<script type="text/javascript">';
$html.= 'affirm.checkout(' . json_encode($payment_method->getCheckoutObject($order)) . ');';
$html.= 'affirm.ui.error.on("close", function(){ window.location= "' . Mage::helper('checkout/url')->getCheckoutUrl() . '";});';
$html.= 'affirm.checkout.post();';
$html.= '</script>';
$html.= '</body></html>';
return $html;
}
}
6 changes: 6 additions & 0 deletions extension/app/code/community/Affirm/Affirm/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class Affirm_Affirm_Helper_Data extends Mage_Core_Helper_Abstract
{

}
Loading

0 comments on commit de84f85

Please sign in to comment.