Skip to content

Instantly share code, notes, and snippets.

@Rahe
Created October 26, 2018 15:00
Show Gist options
  • Save Rahe/53c3c6a580133ca9f6144b7f609ef8d0 to your computer and use it in GitHub Desktop.
Save Rahe/53c3c6a580133ca9f6144b7f609ef8d0 to your computer and use it in GitHub Desktop.
Codeception
<?php
// Create fake resource
$resource = new \StdClass();
$resource->card = new \StdClass();
$resource->card->id = 1;
$resource->card->last4 = '3333';
$resource->card->exp_year = '2019';
$resource->card->exp_month = '01';
$resource->card->brand = 'mastercard';
// Create token for the current user
$token = new \WC_Payment_Token_CC();
$token->set_token( wc_clean( $resource->card->id ) );
$token->set_gateway_id( 'payplug' );
$token->set_last4( wc_clean( $resource->card->last4 ) );
$token->set_expiry_year( wc_clean( $resource->card->exp_year ) );
$token->set_expiry_month( zeroise( (int) wc_clean( $resource->card->exp_month ), 2 ) );
$token->set_card_type( wc_clean( $resource->card->brand ) );
$token->set_user_id( 1 );
$token->add_meta_data( 'mode', 'test' );
$token->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment