Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Commit

Permalink
1.0.7 release
Browse files Browse the repository at this point in the history
- Return last4, type and expiration for storage in Blesta DB
  • Loading branch information
Cherry committed May 25, 2017
1 parent b4fe86a commit e8ba0cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion stripe_plus_gateway/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.6",
"version": "1.0.7",
"name": "Stripe Plus",
"description": "Forked version of the official Stripe gateway which includes updated offsite storage and ACH payments.",
"authors": [
Expand Down
49 changes: 28 additions & 21 deletions stripe_plus_gateway/stripe_plus_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,29 +326,27 @@ public function updateCc(array $card_info, array $contact, $client_reference_id,
$logUrl = "customers/" . $stripe_customer->id . "/sources/" . $account_reference_id;
$request = $card_info;
$result = false;

try {
$card = $stripe_customer->sources->retrieve($account_reference_id);
$card->number = $card_info["card_number"];
$card->exp_month = substr($card_info['card_exp'], -2);
$card->exp_year = substr($card_info['card_exp'], 0, 4);
$card->cvc = $this->ifSet($card_info['card_security_code'], $card->cvc);
$card->name = $this->getCustomerName($card_info, $card->name);
$card->address_line1 = $this->ifSet($card_info['address1'], $card->address_line1);
$card->address_line2 = $this->ifSet($card_info['address2'], $card->address_line2);
$card->address_zip = $this->ifSet($card_info['zip'], $card->address_zip);
$card->address_state = $this->ifSet($card_info['state']['code'], $card->address_state);
$card->address_country = $this->ifSet($card_info['country']['alpha3'], $card->address_country);
$request = $this->objectToArray($card);
$save = $card->save();
$result = array(
'client_reference_id' => $stripe_customer->id,
'reference_id' => $card->id
);
$source = $stripe_customer->sources->retrieve($account_reference_id);
$source->exp_month = substr($card_info['card_exp'], -2);
$source->exp_year = substr($card_info['card_exp'], 0, 4);
$source->name = $this->getCustomerName($card_info, $source->name);
$source->address_line1 = $this->ifSet($card_info['address1'], $source->address_line1);
$source->address_line2 = $this->ifSet($card_info['address2'], $source->address_line2);
$source->address_zip = $this->ifSet($card_info['zip'], $source->address_zip);
$source->address_state = $this->ifSet($card_info['state']['code'], $source->address_state);
$source->address_country = $this->ifSet($card_info['country']['alpha3'], $source->address_country);
$request = $this->objectToArray($source);
$save = $source->save();
$result = $this->parseSource($stripe_customer, $source);
$this->logRequest($logUrl, $request, $save->__toArray(true));
file_put_contents('./debug.json', json_encode($results));
}
catch(Exception $e) {
$errors = $this->handleErrors($e);
$this->logRequest($logUrl, $request, $this->getErrorLog($e, $errors), true);
file_put_contents('./debug-error.json', var_export($e, true));
}

return $result;
Expand Down Expand Up @@ -663,10 +661,7 @@ private function storeSource($contact, $request) {
$result = false;
try {
$source = $stripe_customer->sources->create($request);
$result = array(
'client_reference_id' => $stripe_customer->id,
'reference_id' => $source->id
);
$result = $this->parseSource($stripe_customer, $source);
$this->logRequest($logUrl, $request, $source->__toArray(true));
}
catch(Exception $e) {
Expand All @@ -675,6 +670,18 @@ private function storeSource($contact, $request) {
}
return $result;
}


private function parseSource($stripe_customer, $source){
return [
'client_reference_id' => $stripe_customer->id,
'reference_id' => $source->id,
'last4' => $source->last4,
'type' => strtolower($source->brand),
'expiration' => $source->exp_year . substr("0" . $source->exp_month, -2)
];
}

/**
* Gateway Helper: Removes source from Stripe customer by contact
*
Expand Down

0 comments on commit e8ba0cb

Please sign in to comment.