Skip to content

Commit

Permalink
test: validte order correctly for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Aug 30, 2023
1 parent 8b1fb32 commit 3e1439c
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct( int $orderId ) {
public function getData(): array {
ob_start();
$this->paymentGateway->generate_payfast_form( $this->order->get_id() );
ob_get_clean();
$form = ob_get_clean();

// Make $data_to_send property and _generate_parameter_string function accessible.
$reflectionObject = new ReflectionObject( $this->paymentGateway );
Expand Down Expand Up @@ -63,18 +63,17 @@ public function getData(): array {
$result = array_merge( $result, $this->getAmounts() );

// Add the token and billing date for subscriptions.
if($this->paymentGateway->is_subscription($this->order)){
$result['token'] = sprintf(
'%1$s-%2$s-%2$s-%2$s-%1$s',
random_bytes(8),
random_bytes(4)
);
$result['billing_date'] = date('Y-m-d', strtotime());
if (
$this->paymentGateway->is_subscription( $this->order )
|| $this->paymentGateway->order_contains_subscription( $this->order )
) {
$result['token'] = wp_generate_password(8, false );
$result['billing_date'] = date( 'Y-m-d' );
}

$method = $reflectionObject->getMethod( '_generate_parameter_string' );
$method->setAccessible( true );
$signature = md5($method->invoke( $this->paymentGateway, $result, false, false ));
$signature = md5( $method->invoke( $this->paymentGateway, $result, false, false ) );

// Add the signature.
$result['signature'] = $signature;
Expand Down

0 comments on commit 3e1439c

Please sign in to comment.