Skip to content

Commit b64282e

Browse files
committed
add polyfill for http_response_code
1 parent e08949c commit b64282e

4 files changed

Lines changed: 92 additions & 8 deletions

File tree

includes/class-paystack-deprecated.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,6 @@ public function verify_paystack_transaction() {
286286

287287
@ob_clean();
288288

289-
header( 'HTTP/1.1 200 OK' );
290-
291289
if( isset( $_REQUEST['paystack_txnref'] ) ){
292290

293291
$paystack_url = 'https://api.paystack.co/transaction/verify/' . $_REQUEST['paystack_txnref'];
@@ -388,12 +386,12 @@ public function verify_paystack_transaction() {
388386
*/
389387
public function process_webhooks() {
390388

391-
header( 'HTTP/1.1 200 OK' );
392-
393389
if ( ( strtoupper( $_SERVER['REQUEST_METHOD'] ) != 'POST' ) || ! array_key_exists( 'HTTP_X_PAYSTACK_SIGNATURE', $_SERVER ) ) {
394390
exit;
395391
}
396392

393+
http_response_code(200);
394+
397395
$json = file_get_contents( "php://input" );
398396

399397
$event = json_decode( $json );

includes/class-paystack.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ public function verify_paystack_transaction() {
454454

455455
@ob_clean();
456456

457-
header( 'HTTP/1.1 200 OK' );
458-
459457
if( isset( $_REQUEST['paystack_txnref'] ) ){
460458

461459
$paystack_url = 'https://api.paystack.co/transaction/verify/' . $_REQUEST['paystack_txnref'];
@@ -558,12 +556,12 @@ public function verify_paystack_transaction() {
558556
*/
559557
public function process_webhooks() {
560558

561-
header( 'HTTP/1.1 200 OK' );
562-
563559
if ( ( strtoupper( $_SERVER['REQUEST_METHOD'] ) != 'POST' ) || ! array_key_exists('HTTP_X_PAYSTACK_SIGNATURE', $_SERVER) ) {
564560
exit;
565561
}
566562

563+
http_response_code(200);
564+
567565
$json = file_get_contents( "php://input" );
568566

569567
$event = json_decode( $json );

includes/polyfill.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
if (!function_exists('http_response_code')) {
4+
function http_response_code($code = null)
5+
{
6+
static $defaultCode = 200;
7+
8+
if (null != $code) {
9+
switch ($code) {
10+
case 100: $text = 'Continue'; break; // RFC2616
11+
case 101: $text = 'Switching Protocols'; break; // RFC2616
12+
case 102: $text = 'Processing'; break; // RFC2518
13+
14+
case 200: $text = 'OK'; break; // RFC2616
15+
case 201: $text = 'Created'; break; // RFC2616
16+
case 202: $text = 'Accepted'; break; // RFC2616
17+
case 203: $text = 'Non-Authoritative Information'; break; // RFC2616
18+
case 204: $text = 'No Content'; break; // RFC2616
19+
case 205: $text = 'Reset Content'; break; // RFC2616
20+
case 206: $text = 'Partial Content'; break; // RFC2616
21+
case 207: $text = 'Multi-Status'; break; // RFC4918
22+
case 208: $text = 'Already Reported'; break; // RFC5842
23+
case 226: $text = 'IM Used'; break; // RFC3229
24+
25+
case 300: $text = 'Multiple Choices'; break; // RFC2616
26+
case 301: $text = 'Moved Permanently'; break; // RFC2616
27+
case 302: $text = 'Found'; break; // RFC2616
28+
case 303: $text = 'See Other'; break; // RFC2616
29+
case 304: $text = 'Not Modified'; break; // RFC2616
30+
case 305: $text = 'Use Proxy'; break; // RFC2616
31+
case 306: $text = 'Reserved'; break; // RFC2616
32+
case 307: $text = 'Temporary Redirect'; break; // RFC2616
33+
case 308: $text = 'Permanent Redirect'; break; // RFC-reschke-http-status-308-07
34+
35+
case 400: $text = 'Bad Request'; break; // RFC2616
36+
case 401: $text = 'Unauthorized'; break; // RFC2616
37+
case 402: $text = 'Payment Required'; break; // RFC2616
38+
case 403: $text = 'Forbidden'; break; // RFC2616
39+
case 404: $text = 'Not Found'; break; // RFC2616
40+
case 405: $text = 'Method Not Allowed'; break; // RFC2616
41+
case 406: $text = 'Not Acceptable'; break; // RFC2616
42+
case 407: $text = 'Proxy Authentication Required'; break; // RFC2616
43+
case 408: $text = 'Request Timeout'; break; // RFC2616
44+
case 409: $text = 'Conflict'; break; // RFC2616
45+
case 410: $text = 'Gone'; break; // RFC2616
46+
case 411: $text = 'Length Required'; break; // RFC2616
47+
case 412: $text = 'Precondition Failed'; break; // RFC2616
48+
case 413: $text = 'Request Entity Too Large'; break; // RFC2616
49+
case 414: $text = 'Request-URI Too Long'; break; // RFC2616
50+
case 415: $text = 'Unsupported Media Type'; break; // RFC2616
51+
case 416: $text = 'Requested Range Not Satisfiable'; break; // RFC2616
52+
case 417: $text = 'Expectation Failed'; break; // RFC2616
53+
case 422: $text = 'Unprocessable Entity'; break; // RFC4918
54+
case 423: $text = 'Locked'; break; // RFC4918
55+
case 424: $text = 'Failed Dependency'; break; // RFC4918
56+
case 426: $text = 'Upgrade Required'; break; // RFC2817
57+
case 428: $text = 'Precondition Required'; break; // RFC6585
58+
case 429: $text = 'Too Many Requests'; break; // RFC6585
59+
case 431: $text = 'Request Header Fields Too Large'; break; // RFC6585
60+
61+
case 500: $text = 'Internal Server Error'; break; // RFC2616
62+
case 501: $text = 'Not Implemented'; break; // RFC2616
63+
case 502: $text = 'Bad Gateway'; break; // RFC2616
64+
case 503: $text = 'Service Unavailable'; break; // RFC2616
65+
case 504: $text = 'Gateway Timeout'; break; // RFC2616
66+
case 505: $text = 'HTTP Version Not Supported'; break; // RFC2616
67+
case 506: $text = 'Variant Also Negotiates'; break; // RFC2295
68+
case 507: $text = 'Insufficient Storage'; break; // RFC4918
69+
case 508: $text = 'Loop Detected'; break; // RFC5842
70+
case 510: $text = 'Not Extended'; break; // RFC2774
71+
case 511: $text = 'Network Authentication Required'; break; // RFC6585
72+
73+
default:
74+
$code = 500;
75+
$text = 'Internal Server Error';
76+
}
77+
78+
$defaultCode = $code;
79+
80+
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
81+
header($protocol . ' ' . $code . ' ' . $text);
82+
}
83+
84+
return $defaultCode;
85+
}
86+
}

woo-paystack.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function tbz_wc_paystack_init() {
3232
require_once dirname( __FILE__ ) . '/includes/class-paystack-deprecated.php';
3333
}
3434

35+
require_once dirname( __FILE__ ) . '/includes/polyfill.php';
36+
3537
/**
3638
* Add Settings link to the plugin entry in the plugins menu
3739
**/

0 commit comments

Comments
 (0)