mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 07:24:35 -04:00
Merge pull request #4398 from beganovich/v5-stripe-issue-with-refunding
(v5) Fix issues with Stripe refunding
This commit is contained in:
commit
686a98eec4
@ -111,14 +111,15 @@ class CreditCard
|
|||||||
private function processSuccessfulPayment()
|
private function processSuccessfulPayment()
|
||||||
{
|
{
|
||||||
$stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method);
|
$stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method,
|
'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method,
|
||||||
'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)),
|
'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)),
|
||||||
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision),
|
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision),
|
||||||
'transaction_reference' => $this->stripe->payment_hash->data->server_response->id,
|
'transaction_reference' => optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]);
|
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]);
|
||||||
$this->stripe->payment_hash->save();
|
$this->stripe->payment_hash->save();
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
* Processes the gateway response for credit card authorization.
|
* Processes the gateway response for credit card authorization.
|
||||||
*
|
*
|
||||||
* @param Request $request The returning request object
|
* @param Request $request The returning request object
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
*/
|
*/
|
||||||
public function authorizeResponse($request)
|
public function authorizeResponse($request)
|
||||||
{
|
{
|
||||||
@ -189,7 +189,7 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
* Process the payment with gateway.
|
* Process the payment with gateway.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return Factory|View|void
|
* @return Factory|View|void
|
||||||
*/
|
*/
|
||||||
public function processPaymentView(array $data)
|
public function processPaymentView(array $data)
|
||||||
{
|
{
|
||||||
@ -209,7 +209,7 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id])
|
->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id])
|
||||||
->with('missing_required_fields', $this->required_fields);
|
->with('missing_required_fields', $this->required_fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->payment_method->paymentResponse($request);
|
return $this->payment_method->paymentResponse($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$customer) {
|
if (!$customer) {
|
||||||
throw new Exception('Unable to create gateway customer');
|
throw new \Exception('Unable to create gateway customer');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $customer;
|
return $customer;
|
||||||
@ -289,37 +289,48 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
$response = $this->stripe
|
/** Response from Stripe SDK/API. */
|
||||||
->refunds
|
$response = null;
|
||||||
->create(['charge' => $payment->transaction_reference, 'amount' => $amount]);
|
|
||||||
|
|
||||||
// $response = $this->gateway
|
try {
|
||||||
// ->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
|
$response = $this->stripe
|
||||||
// ->send();
|
->refunds
|
||||||
|
->create(['charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision)]);
|
||||||
|
|
||||||
if ($response->status == $response::STATUS_SUCCEEDED) {
|
if ($response->status == $response::STATUS_SUCCEEDED) {
|
||||||
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),
|
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
|
||||||
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
|
|
||||||
|
return [
|
||||||
|
'transaction_reference' => $response->charge,
|
||||||
|
'transaction_response' => json_encode($response),
|
||||||
|
'success' => $response->status == $response::STATUS_SUCCEEDED ? true : false,
|
||||||
|
'description' => $response->metadata,
|
||||||
|
'code' => $response,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'transaction_reference' => $response->charge,
|
'transaction_reference' => null,
|
||||||
'transaction_response' => json_encode($response),
|
'transaction_response' => json_encode($response),
|
||||||
'success' => $response->status == $response::STATUS_SUCCEEDED ? true : false,
|
'success' => false,
|
||||||
'description' => $response->metadata,
|
'description' => $response->failure_reason,
|
||||||
'code' => $response,
|
'code' => 422,
|
||||||
|
];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||||
|
|
||||||
|
info($e->getMessage());
|
||||||
|
|
||||||
|
return [
|
||||||
|
'transaction_reference' => null,
|
||||||
|
'transaction_response' => json_encode($response),
|
||||||
|
'success' => false,
|
||||||
|
'description' => $e->getMessage(),
|
||||||
|
'code' => 422,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),
|
|
||||||
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'transaction_reference' => null,
|
|
||||||
'transaction_response' => json_encode($response),
|
|
||||||
'success' => false,
|
|
||||||
'description' => $response->failure_reason,
|
|
||||||
'code' => 422,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verificationView(ClientGatewayToken $payment_method)
|
public function verificationView(ClientGatewayToken $payment_method)
|
||||||
@ -395,8 +406,8 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
* https://stripe.com/docs/api/payment_methods/detach
|
* https://stripe.com/docs/api/payment_methods/detach
|
||||||
*
|
*
|
||||||
* @param ClientGatewayToken $token
|
* @param ClientGatewayToken $token
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function detach(ClientGatewayToken $token)
|
public function detach(ClientGatewayToken $token)
|
||||||
{
|
{
|
||||||
$stripe = new StripeClient(
|
$stripe = new StripeClient(
|
||||||
@ -411,7 +422,7 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCompanyGatewayId(): int
|
public function getCompanyGatewayId(): int
|
||||||
{
|
{
|
||||||
return $this->company_gateway->id;
|
return $this->company_gateway->id;
|
||||||
|
@ -132,7 +132,7 @@ trait AppSetup
|
|||||||
|
|
||||||
if (is_null($position)) {
|
if (is_null($position)) {
|
||||||
$words_count > 1 ? $env[] = "{$property}=" . '"' . $value . '"' . "\n" : $env[] = "{$property}=" . $value . "\n";
|
$words_count > 1 ? $env[] = "{$property}=" . '"' . $value . '"' . "\n" : $env[] = "{$property}=" . $value . "\n";
|
||||||
} else if ($words_count > 1) {
|
} elseif ($words_count > 1) {
|
||||||
$env[$position] = "{$property}=" . '"' . $value . '"' . "\n"; // If value of variable is more than one word, surround with quotes.
|
$env[$position] = "{$property}=" . '"' . $value . '"' . "\n"; // If value of variable is more than one word, surround with quotes.
|
||||||
} else {
|
} else {
|
||||||
$env[$position] = "{$property}=" . $value . "\n"; // Just a normal variable update, with prexisting keys.
|
$env[$position] = "{$property}=" . $value . "\n"; // Just a normal variable update, with prexisting keys.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user