Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Saved Credit Card Support and Partial Refund Support #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions app/code/community/Inchoo/Stripe/Block/Creditcard/Management.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

require_once('stripe/lib/stripe.php');

class Inchoo_Stripe_Block_Creditcard_Management extends Mage_Customer_Block_Account_Dashboard
{
protected $stripe;

function __construct()
{
parent::__construct();
$this->setTemplate('stripe/creditcard/index.phtml');
$this->stripe = Mage::getModel('stripe/paymentmethod');
}


function creditCard()
{
$result = Mage::registry('stripe_result');
if (!empty($result))
{
$token = ($result->success) ? $result->creditCard->token : $result->params['paymentMethodToken'];
}
else
{
$token = Mage::app()->getRequest()->getParam('token');
}
return $this->stripe->storedCard($token);
}

function getPostParam($index, $default='')
{
$result = Mage::registry('stripe_result');
if (!empty($result))
{
$indices = explode('.', $index);
$value = $result->params;
foreach($indices as $key)
{
if (is_array($value[$key]))
{
$value = $value[$key];
}
else
{
return $value[$key];
}
}

}
else
{
return $default;
}
}

function errors()
{
$result = Mage::registry('stripe_result');
if (!empty($result))
{
return Mage::helper('stripe/messages')->errors(explode("\n", $result->message));
}
}

function hasErrors()
{
$result = Mage::registry('stripe_result');
return !empty($result) && !$result->success;
}

function buildTrData($redirectUrl)
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($this->stripe->exists($customer->getId()))
{
return stripe_TransparentRedirect::createCreditCardData(array(
'redirectUrl' => $redirectUrl,
'creditCard' => array('customerId' => $customer->getId())
));
}
else
{
$credit_card_billing = array();
$billing = $customer->getDefaultBilling();
if ($billing)
{
$address = Mage::getModel('customer/address')->load($billing);
$credit_card_billing['billingAddress'] = $this->stripe->tostripeAddress($address);
}
return stripe_TransparentRedirect::createCustomerData(array(
'redirectUrl' => $redirectUrl,
'customer' => array(
'id' => $customer->getId(),
'firstName' => $customer->getFirstname(),
'lastName' => $customer->getLastname(),
'company' => $customer->getCompany(),
'phone' => $customer->getTelephone(),
'fax' => $customer->getFax(),
'email' => $customer->getEmail(),
'creditCard' => $credit_card_billing
)));
}
}

function hasDefaultAddress()
{
$defaultAddress = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling();
return !is_null($defaultAddress);
}
}
30 changes: 30 additions & 0 deletions app/code/community/Inchoo/Stripe/Block/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

class Inchoo_Stripe_Block_Form extends Mage_Payment_Block_Form_Cc
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('stripe/form.phtml');
}

protected function _toHtml()
{
if ($this->getMethod()->getCode() != Mage::getSingleton('stripe/paymentMethod')->getCode()) {
return null;
}

return parent::_toHtml();
}

public function setMethodInfo()
{
$payment = Mage::getSingleton('checkout/type_onepage')
->getQuote()
->getPayment();
$this->setMethod($payment->getMethodInstance());

return $this;
}

}
10 changes: 10 additions & 0 deletions app/code/community/Inchoo/Stripe/Block/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Inchoo_Stripe_Block_Info extends Mage_Payment_Block_Info
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('stripe/info.phtml');
}
}
2 changes: 2 additions & 0 deletions app/code/community/Inchoo/Stripe/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
*/
class Inchoo_Stripe_Helper_Data extends Mage_Core_Helper_Abstract
{


}
Loading