Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Refactor: update gateways to support $gatewayData introduced in GiveWP 2.22.0 #26

Merged
merged 4 commits into from
Sep 16, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const handleSubmitRequest = async (values, setError, gateway: Gateway) => {

const request = await postData(donateUrl, {
...values,
...beforeCreatePaymentGatewayResponse,
gatewayData: beforeCreatePaymentGatewayResponse,
});

if (!request.response.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getLegacyFormFieldMarkup(int $formId, array $args): string
*/
public function createPayment(Donation $donation, $gatewayData)
{
$intent = $this->request()->get('testGatewayIntent');
$intent = $gatewayData['testGatewayIntent'];
$transactionId = "test-gateway-transaction-id-{$donation->id}";

$donation->status = DonationStatus::COMPLETE();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ public function createPayment(Donation $donation, $gatewayData): GatewayCommand
/**
* Get data from client request
*/
$request = $this->request();
$stripeConnectedAccountKey = $request->get('stripeConnectedAccountKey');
$stripePaymentIntentId = $request->get('stripePaymentIntentId');
$stripeConnectedAccountKey = $gatewayData['stripeConnectedAccountKey'];
$stripePaymentIntentId = $gatewayData['stripePaymentIntentId'];

/**
* Get or create a Stripe customer
Expand Down
6 changes: 4 additions & 2 deletions tests/Feature/Controllers/BlockRenderControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace TestsNextGen\Feature\Controllers;

use Give\NextGen\DonationForm\Actions\GenerateDonationFormViewRouteUrl;
use Give\NextGen\DonationForm\Blocks\DonationFormBlock\Controllers\BlockRenderController;
use GiveTests\TestCase;
Expand All @@ -8,10 +10,10 @@ class BlockRenderControllerTest extends TestCase
{
/**
* @unreleased
*
*
* @return void
*/
public function testShouldReturnIframe()
public function testShouldReturnIframe()
{
$formId = 1;
$formTemplateId = 'classic';
Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/Gateways/NextGenTestGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace TestsNextGen\Feature\Gateways;

use Give\Donations\Models\Donation;
use Give\Framework\PaymentGateways\Commands\RespondToBrowser;
use Give\NextGen\Gateways\NextGenTestGateway\NextGenTestGateway;
use GiveTests\TestCase;
use GiveTests\TestTraits\RefreshDatabase;

class NextGenTestGatewayTest extends TestCase
{
use RefreshDatabase;

public function testShouldCreatePaymentAndReturnRespondToBrowser()
{
$gateway = new NextGenTestGateway();
$donation = Donation::factory()->create();
$gatewayData = ['testGatewayIntent' => 'test-gateway-intent'];

$response = $gateway->createPayment($donation, $gatewayData);

$command = new RespondToBrowser([
'donation' => $donation->toArray(),
'redirectUrl' => give_get_success_page_uri(),
'intent' => $gatewayData['testGatewayIntent']
]);

$this->assertInstanceOf(RespondToBrowser::class, $response);
$this->assertSame($command->data, $response->data);
}
}