You are here

public function PaymentIntentTest::testCreatePaymentIntent in Commerce Stripe 8

Tests creating payment intents.

@dataProvider dataProviderCreatePaymentIntent

Parameters

string $payment_method_token: The test payment method token.

bool $capture: The capture.

string $initial_status: The initial payment intent status.

string $confirmed_status: The confirmed payment intent status.

File

tests/src/Kernel/PaymentIntentTest.php, line 38

Class

PaymentIntentTest
Payment intent tests.

Namespace

Drupal\Tests\commerce_stripe\Kernel

Code

public function testCreatePaymentIntent($payment_method_token, $capture, $initial_status, $confirmed_status) {
  $gateway = $this
    ->generateGateway();
  $plugin = $gateway
    ->getPlugin();
  assert($plugin instanceof StripeInterface);
  $payment_method = $this
    ->prophesize(PaymentMethodInterface::class);
  $payment_method
    ->getRemoteId()
    ->willReturn($payment_method_token);
  $order = $this
    ->prophesize(OrderInterface::class);
  $order
    ->get('payment_method')
    ->willReturn((object) [
    'entity' => $payment_method
      ->reveal(),
  ]);
  $order
    ->getTotalPrice()
    ->willReturn(new Price('15.00', 'USD'));
  $order
    ->getStoreId()
    ->willReturn(1111);
  $order
    ->id()
    ->willReturn(9999);
  $order
    ->getCustomer()
    ->willReturn(User::getAnonymousUser());
  $order
    ->setData('stripe_intent', Argument::containingString('pi_'))
    ->willReturn($order
    ->reveal());
  $order
    ->save()
    ->willReturn(NULL);
  $intent = $plugin
    ->createPaymentIntent($order
    ->reveal(), $capture);
  $this
    ->assertEquals($capture ? 'automatic' : 'manual', $intent->capture_method);
  $this
    ->assertEquals($initial_status, $intent->status);
  $this
    ->assertEquals($intent->currency, 'usd');
  $this
    ->assertEquals($intent->amount, 1500);
  $intent = $intent
    ->confirm();
  $this
    ->assertEquals($confirmed_status, $intent->status);
}