1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\PaymentProtocol; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Crypto\Random\Random; |
6
|
|
|
use BitWasp\Bitcoin\PaymentProtocol\Protobufs\Payment; |
7
|
|
|
use BitWasp\Bitcoin\PaymentProtocol\Protobufs\PaymentACK; |
8
|
|
|
use BitWasp\Bitcoin\PaymentProtocol\Protobufs\PaymentRequest; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
class HttpResponse |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param $data |
15
|
|
|
* @param $contentType |
16
|
|
|
* @return Response |
17
|
|
|
*/ |
18
|
|
|
public function raw($data, $contentType) |
19
|
|
|
{ |
20
|
|
|
$random = new Random(); |
21
|
|
|
$filename = "r" . $random->bytes(12)->getHex() . "." . $contentType; |
22
|
|
|
|
23
|
|
|
$response = new Response(); |
24
|
|
|
$response->setContent($data); |
25
|
|
|
|
26
|
|
|
$response->headers->set('Content-Type', 'application/bitcoin-' . $contentType); |
27
|
|
|
$response->headers->set('Content-Disposition', 'inline; filename=' . $filename); |
28
|
|
|
$response->headers->set('Content-Transfer-Encoding', 'binary'); |
29
|
|
|
$response->headers->set('Expires', '0'); |
30
|
|
|
$response->headers->set('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); |
31
|
|
|
|
32
|
|
|
return $response; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param PaymentRequest $request |
37
|
|
|
* @return Response |
38
|
|
|
*/ |
39
|
|
|
public function paymentRequest(PaymentRequest $request) |
40
|
|
|
{ |
41
|
|
|
return $this->raw($request->serialize(), 'paymentrequest'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Payment $payment |
46
|
|
|
* @return Response |
47
|
|
|
*/ |
48
|
|
|
public function payment(Payment $payment) |
49
|
|
|
{ |
50
|
|
|
return $this->raw($payment->serialize(), 'payment'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param PaymentACK $ack |
55
|
|
|
* @return Response |
56
|
|
|
*/ |
57
|
|
|
public function paymentAck(PaymentACK $ack) |
58
|
|
|
{ |
59
|
|
|
return $this->raw($ack->serialize(), 'paymentack'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|