Giter Club home page Giter Club logo

Comments (2)

d1str4ught avatar d1str4ught commented on June 12, 2024

Hm, I checked my DB and there is no transaction_id since I use Stripe SCA.

from attendize.

d1str4ught avatar d1str4ught commented on June 12, 2024

Solved. We need to get our payment identifier from the payment_intent and initiate the refund via that.
Sorry for not doing a proper commit; we have it on our own version control system (svn), and I don't want to check it out.

StripeSCA.php:

    public function refundTransaction($order, $refund_amount, $refund_application_fee)
    {		
		$paymentIntentResponse = $this->gateway->fetchPaymentIntent([
			'paymentIntentReference' => $order->payment_intent,
		])->send();
		
		if ($paymentIntentResponse->isSuccessful()) {
			$data = $paymentIntentResponse->getData();
			Log::debug($data);
			$chargeId = $data['latest_charge'];
			
			$request = $this->gateway->refund([
				'transactionReference' => $chargeId,
				'amount' => $refund_amount,
				'refundApplicationFee' => $refund_application_fee
			]);

			$response = $request->send();

			if ($response->isSuccessful()) {
				$refundResponse['successful'] = true;
			} else {
				$refundResponse['successful'] = false;
				$refundResponse['error_message'] = $response->getMessage();
			}
		} else {
			$refundResponse['successful'] = false;
			$refundResponse['error_message'] = $response->getMessage();
		}
		
		return $refundResponse;
    }

Also, modify checkValidRefundState in OrderRefund.php so that it will not throw an exception (because originally it only checks for transaction_id, but we don't have that when using SCA, only the payment_intent field.

    private function checkValidRefundState()
    {
        $errorMessage = false;
        if (!$this->order->transaction_id && !$this->order->payment_intent) {
            $errorMessage = trans("Controllers.order_cant_be_refunded");
        }
        if ($this->order->is_refunded) {
            $errorMessage = trans('Controllers.order_already_refunded');
        } elseif ($this->maximumRefundableAmount->isZero()) {
            $errorMessage = trans('Controllers.nothing_to_refund');
        } elseif ($this->refundAmount->isGreaterThan($this->maximumRefundableAmount)) {
            // Error if the partial refund tries to refund more than allowed
            $errorMessage = trans('Controllers.maximum_refund_amount', [
                'money' => $this->maximumRefundableAmount->display(),
            ]);
        }
        if ($errorMessage) {
            throw new OrderRefundException($errorMessage);
        }
    }

from attendize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.