makeTestData(); $this->withoutMiddleware( ThrottleRequests::class ); } public function testWebhooks() { $hook = json_decode($this->webhook_string, true); $this->assertIsArray($hook); } public function testPaymentCreation() { $hook = json_decode($this->webhook_string, true); $company_gateway = $this->buildGateway(); $invoice = Invoice::factory()->create([ 'company_id' => $this->company->id, 'user_id' => $this->user->id, 'client_id' => $this->client->id, 'number' => $this->invoice_number, 'status_id' => 2, 'amount' => $this->amount, 'balance' => $this->amount, ]); $hash_data = [ 'invoices' => [ ['invoice_id' => $invoice->hashed_id, 'amount' => $this->amount], ], 'credits' => 0, 'amount_with_fee' => $this->amount, 'pre_payment' => false, 'frequency_id' => null, 'remaining_cycles' => null, 'is_recurring' => false, ]; $payment_hash = new PaymentHash; $payment_hash->hash = Str::random(32); $payment_hash->data = $hash_data; $payment_hash->fee_total = 0; $payment_hash->fee_invoice_id = $invoice->id; $payment_hash->save(); $driver = $company_gateway->driver($this->client); $driver->setPaymentHash($payment_hash); $source = 'paypal'; $transaction_reference = $hook['resource']['purchase_units'][0]['payments']['captures'][0]['id']; $amount = $hook['resource']['purchase_units'][0]['payments']['captures'][0]['amount']['value']; $data = [ 'payment_type' => 3, 'amount' => $amount, 'transaction_reference' => $transaction_reference, 'gateway_type_id' => GatewayType::PAYPAL, ]; $payment = $driver->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); $this->assertNotNull($payment); } private function buildGateway() { $config = new \stdClass; $config->merchantId = $this->merchant_id; $config->status = 'activated'; $config->consent = 'true'; $config->emailVerified = 'true'; $config->permissions = 'true'; $config->returnMessage = 'true'; $config->paymentsReceivable = 'Yes'; $cg = new CompanyGateway; $cg->company_id = $this->company->id; $cg->user_id = $this->user->id; $cg->gateway_key = '80af24a6a691230bbec33e930ab40666'; $cg->require_cvv = true; $cg->require_billing_address = true; $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt($config); $cg->save(); $fees_and_limits = new stdClass; $fees_and_limits->{3} = new FeesAndLimits; $cg->fees_and_limits = $fees_and_limits; $cg->save(); return $cg; } }