mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-14 06:36:46 +00:00
🚀 feat(migration): add zap endpoint field to payment events table
🎨 refactor(profile): update payment logic and button display 🔧 fix(nostrZap): change relay URL to secure WebSocket protocol
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('payment_events', function (Blueprint $table) {
|
||||||
|
$table->string('zap_endpoint')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('payment_events', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -16,7 +16,7 @@ export default (livewireComponent) => ({
|
|||||||
relayUrl: 'wss://simple-test-relay.steuernsindraub21.xyz',
|
relayUrl: 'wss://simple-test-relay.steuernsindraub21.xyz',
|
||||||
},
|
},
|
||||||
local: {
|
local: {
|
||||||
relayUrl: 'ws://simple-test-relay.steuernsindraub21.xyz',
|
relayUrl: 'wss://simple-test-relay.steuernsindraub21.xyz',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const relayUrl = config[env]?.relayUrl || config['local'].relayUrl;
|
const relayUrl = config[env]?.relayUrl || config['local'].relayUrl;
|
||||||
@@ -41,6 +41,8 @@ export default (livewireComponent) => ({
|
|||||||
const callbackData = await callbackResponse.json();
|
const callbackData = await callbackResponse.json();
|
||||||
const zapEndpoint = callbackData.callback;
|
const zapEndpoint = callbackData.callback;
|
||||||
|
|
||||||
|
livewireComponent.call('updateZapEndpoint', zapEndpoint);
|
||||||
|
|
||||||
const zapEvent = nip57.makeZapRequest({
|
const zapEvent = nip57.makeZapRequest({
|
||||||
profile: sender,
|
profile: sender,
|
||||||
event: event.id,
|
event: event.id,
|
||||||
|
|||||||
@@ -79,79 +79,38 @@ on([
|
|||||||
$this->currentPleb->load('paymentEvents');
|
$this->currentPleb->load('paymentEvents');
|
||||||
}
|
}
|
||||||
$this->loadEvents();
|
$this->loadEvents();
|
||||||
$this->searchPaymentEvent();
|
$this->listenForPayment();
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$listenForPayment = function () {
|
$listenForPayment = function () {
|
||||||
if (!$this->currentYearIsPaid) {
|
$paymentEvent = $this->currentPleb
|
||||||
$this->searchPaymentEvent();
|
->paymentEvents()
|
||||||
|
->where('year', date('Y'))
|
||||||
|
->first();
|
||||||
|
if ($paymentEvent && !$paymentEvent->paid && $paymentEvent->zap_endpoint && !$this->currentYearIsPaid) {
|
||||||
|
$response = Http::get($paymentEvent->zap_endpoint);
|
||||||
|
|
||||||
|
if (!isset($response->json()['tag'])) {
|
||||||
|
$paymentEvent->update(['paid' => true]);
|
||||||
|
$this->currentYearIsPaid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($paymentEvent && $paymentEvent->paid && !$this->currentYearIsPaid) {
|
||||||
|
$this->payments = $paymentEvent = $this->currentPleb
|
||||||
|
->paymentEvents()
|
||||||
|
->get();
|
||||||
|
$this->currentYearIsPaid = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$searchPaymentEvent = function () {
|
$updateZapEndpoint = function ($zapEndpoint) {
|
||||||
$subscription = new Subscription();
|
$this->currentPleb
|
||||||
$subscriptionId = $subscription->setId();
|
->paymentEvents()
|
||||||
|
->where('year', date('Y'))
|
||||||
$filter1 = new Filter();
|
->first()
|
||||||
$filter1->setKinds([9735]);
|
->update(['zap_endpoint' => $zapEndpoint]);
|
||||||
$filters = [$filter1];
|
|
||||||
|
|
||||||
$requestMessage = new RequestMessage($subscriptionId, $filters);
|
|
||||||
|
|
||||||
$relays = [
|
|
||||||
new Relay(config('services.relay')),
|
|
||||||
];
|
|
||||||
$relaySet = new RelaySet();
|
|
||||||
$relaySet->setRelays($relays);
|
|
||||||
|
|
||||||
$request = new Request($relaySet, $requestMessage);
|
|
||||||
$response = $request->send();
|
|
||||||
|
|
||||||
if (count($response[config('services.relay')]) > 0) {
|
|
||||||
$this->payments = collect($response[config('services.relay')])
|
|
||||||
->map(fn($event)
|
|
||||||
=> [
|
|
||||||
'id' => $event->event->id,
|
|
||||||
'kind' => $event->event->kind,
|
|
||||||
'content' => $event->event->content,
|
|
||||||
'pubkey' => $event->event->pubkey,
|
|
||||||
'tags' => $event->event->tags,
|
|
||||||
'created_at' => $event->event->created_at,
|
|
||||||
])
|
|
||||||
->filter(fn($payment)
|
|
||||||
=> collect($payment['tags'])->firstWhere('0', 'p')[1] === $this->currentPubkey
|
|
||||||
&& json_decode(
|
|
||||||
collect($payment['tags'])->firstWhere('0', 'description')[1],
|
|
||||||
true,
|
|
||||||
512,
|
|
||||||
JSON_THROW_ON_ERROR,
|
|
||||||
)['content'] == date('Y'))
|
|
||||||
->values()
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$this->yearsPaid = collect($this->payments)->map(fn($payment)
|
|
||||||
=> [
|
|
||||||
'year' => $payment['content'],
|
|
||||||
'amount' => collect(
|
|
||||||
json_decode(
|
|
||||||
collect($payment['tags'])->firstWhere('0', 'description')[1],
|
|
||||||
true,
|
|
||||||
512,
|
|
||||||
JSON_THROW_ON_ERROR,
|
|
||||||
)['tags'],
|
|
||||||
)->firstWhere('0', 'amount')[1] / 1000,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->currentYearIsPaid = collect($this->yearsPaid)->contains(
|
|
||||||
fn($yearPaid) => $yearPaid['year'] == date('Y') && $yearPaid['amount'] == $this->amountToPay,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($this->currentYearIsPaid) {
|
|
||||||
$this->qrCode = null;
|
|
||||||
$this->currentPleb->paymentEvents->first()->update(['paid' => true]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$save = function ($type) {
|
$save = function ($type) {
|
||||||
@@ -466,17 +425,17 @@ $loadEvents = function () {
|
|||||||
class="break-all">{{ $currentPleb->paymentEvents->first()->event_id }}</span>
|
class="break-all">{{ $currentPleb->paymentEvents->first()->event_id }}</span>
|
||||||
</p>
|
</p>
|
||||||
<div>
|
<div>
|
||||||
@if(false && isset($events[0]))
|
@if(isset($events[0]))
|
||||||
<p>{{ $events[0]['content'] }}</p>
|
<p>{{ $events[0]['content'] }}</p>
|
||||||
<div class="mt-8">
|
<div class="mt-8">
|
||||||
@if(!$invoice && !$currentYearIsPaid)
|
@if(!$invoice && !$currentYearIsPaid)
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
<button
|
<button
|
||||||
@click="zap('{{ date('Y') }}', '{{ $currentPubkey }}', {{ $amountToPay }}, '{{ config('app.env') }}')"
|
@click="zap('Mitgliedsbeitrag {{ date('Y') }} von {{ $currentPubkey }}', '{{ $currentPubkey }}', {{ $amountToPay }}, '{{ config('app.env') }}')"
|
||||||
class="btn text-2xl dark:bg-gray-800 border-gray-200 dark:border-gray-700/60 hover:border-gray-300 dark:hover:border-gray-600 text-green-500"
|
class="btn text-2xl dark:bg-gray-800 border-gray-200 dark:border-gray-700/60 hover:border-gray-300 dark:hover:border-gray-600 text-green-500"
|
||||||
>
|
>
|
||||||
<i class="fa-sharp-duotone fa-solid fa-bolt-lightning mr-2"></i>
|
<i class="fa-sharp-duotone fa-solid fa-bolt-lightning mr-2"></i>
|
||||||
Zap
|
Zap {{ $amountToPay }} Sats
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
@@ -545,18 +504,18 @@ $loadEvents = function () {
|
|||||||
<div
|
<div
|
||||||
class="text-left font-medium text-gray-800 dark:text-gray-100">
|
class="text-left font-medium text-gray-800 dark:text-gray-100">
|
||||||
<span class="sm:hidden">Sats:</span>
|
<span class="sm:hidden">Sats:</span>
|
||||||
{{ collect(json_decode(collect($payment['tags'])->firstWhere('0', 'description')[1], true, 512, JSON_THROW_ON_ERROR)['tags'])->firstWhere('0', 'amount')[1] / 1000 }}
|
{{ $payment->amount }}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
|
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
|
||||||
<div
|
<div
|
||||||
class="text-left"><span
|
class="text-left"><span
|
||||||
class="sm:hidden">Jahr:</span>{{ $payment['content'] }}
|
class="sm:hidden">Jahr:</span>{{ $payment->year }}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
|
<td class="w-full block md:w-auto md:table-cell py-0.5 md:py-2">
|
||||||
<div
|
<div
|
||||||
class="text-left font-medium break-all">{{ $payment['id'] }}</div>
|
class="text-left font-medium break-all">{{ $payment->event_id }}</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
Reference in New Issue
Block a user