Plugin Directory

Changeset 2914592


Ignore:
Timestamp:
05/19/2023 06:24:21 AM (3 years ago)
Author:
zipmoney
Message:

plugin support wordpress 6.2 and woocommerce 7.5.1

Location:
zipmoney-payments-woocommerce
Files:
188 added
7 edited

Legend:

Unmodified
Added
Removed
  • zipmoney-payments-woocommerce/trunk/README.txt

    r2806192 r2914592  
    33Tags: zipmoney payments woocommerce, zipmoney payments module for woocommerce, zipmoney woocommerce addon , zipmoney payment gateway for woocommerce, zipmoney for woocommerce, zipmoney payment gateway for wordpress, buy now pay later, zippay woocommerce plugin, Own it now, pay later, Zip Co, Zip
    44Requires at least: WP 4.0
    5 Tested up to: 6.0.3
    6 Stable tag: 2.3.16
     5Tested up to: 6.2
     6Stable tag: 2.3.17
    77License: GPLv2 or later License http://www.gnu.org/licenses/gpl-2.0.html
    88
     
    218218
    219219= 2.3.16 =
    220 * Fixed some security related issues
     220* Fixed some security related
     221
     222= 2.3.17 =
     223* Test plugin with wordpress 6.2 and woocommerce 7.5.1
  • zipmoney-payments-woocommerce/trunk/includes/class-wc-zipmoney-payment-gateway.php

    r2806192 r2914592  
    2424    public $description = 'Own the way you pay';
    2525
    26     public $version = '2.3.16';
     26    public $version = '2.3.17';
    2727
    2828    public $supports = array( 'products', 'refunds' );
  • zipmoney-payments-woocommerce/trunk/tests/bootstrap.php

    r2283719 r2914592  
    1818 */
    1919function _manually_load_plugin() {
    20     require '/tmp/wordpress/wp-content/plugins/woocommerce/woocommerce.php';
     20    require '/tmp/wordpress/wp-content/plugins/woocommerce/woocommerce.php';
    2121    require dirname( dirname( __FILE__ ) ) . '/zipmoney-payment-gateway.php';
    2222}
  • zipmoney-payments-woocommerce/trunk/tests/test-charge-api.php

    r2374952 r2914592  
    66 * @package Woocommerce_Zipmoneypayment_Apiv2
    77 */
    8 class ChargeApiTest extends WC_ZipmoneyPaymentGatewayTestMain
    9 {
    10 
    11     public function charge_result_provider()
    12     {
    13         $states = array('captured', 'authorised', 'cancelled')  ;
    14 
    15         $result = array();
    16 
    17         foreach($states as $state){
    18             $result[] = array(new \zipMoney\Model\Charge(
    19                 array(
    20                     'id' => 'test',
    21                     'state' => $state
    22                 )
    23             ));
    24         }
    25 
    26         return $result;
    27     }
    28 
    29     public function exception_provider()
    30     {
    31         return array(
    32             array(new \Exception()),
    33             array(new \zipMoney\ApiException())
    34         );
    35     }
    36 
    37     /**
    38      * @dataProvider charge_result_provider
    39      */
    40     public function test_create_charge($charge_result)
    41     {
    42         $api_instance = $this->getMock('\zipMoney\Api\ChargesApi');
    43         $api_instance->expects($this->once())
    44             ->method('chargesCreate')
    45             ->will($this->returnValue($charge_result));
    46 
    47         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    48             $this->payment_gateway,
    49             $api_instance
    50         );
    51 
    52         $order = self::get_mock_order();
    53 
    54         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->create_charge($this->WC_Session, 'key', $order);
    55 
    56         $this->assertArrayHasKey('success', $response);
    57         $this->assertArrayHasKey('message', $response);
    58         $this->assertArrayHasKey('order', $response);
    59 
    60         if($charge_result->getState() == 'cancelled'){
    61             $this->assertFalse($response['success']);
    62         } else {
    63             $this->assertTrue($response['success']);
    64         }
    65     }
    66 
    67 
    68     /**
    69      * @dataProvider exception_provider
    70      */
    71     public function test_create_charge_with_exception($exception)
    72     {
    73         $api_instance = $this->getMock('\zipMoney\Api\ChargesApi');
    74         $api_instance->expects($this->once())
    75             ->method('chargesCreate')
    76             ->will($this->throwException($exception));
    77 
    78         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    79             $this->payment_gateway,
    80             $api_instance
    81         );
    82 
    83         $order = self::get_mock_order();
    84 
    85         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->create_charge($this->WC_Session, 'key', $order);
    86         $this->assertArrayHasKey('success', $response);
    87         $this->assertArrayHasKey('message', $response);
    88 
    89         $this->assertFalse($response['success']);
    90     }
    91 
    92     /**
    93      * @dataProvider charge_result_provider
    94      */
    95     public function test_capture_charge($charge_result)
    96     {   
    97         $api_instance = $this->getMock('\zipMoney\Api\ChargesApi');
    98         $api_instance->expects($this->any())
    99             ->method('chargesCapture')
    100             ->will($this->returnValue($charge_result));
    101 
    102         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    103             $this->payment_gateway,
    104             $api_instance
    105         );
    106 
    107         $order = self::get_mock_order();
    108         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge($order, 'key');
    109         $this->assertFalse($response);
    110 
    111         //order status is not authorized
    112         update_post_meta($this->get_order_id($order), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id');
    113         $order = self::get_mock_order('processing');
    114         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge($order, 'key');
    115         $this->assertFalse($response);
    116 
    117         $order = self::get_mock_order(WC_Zipmoney_Payment_Gateway_Config::ZIP_ORDER_STATUS_AUTHORIZED_KEY_COMPARE);
    118         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge($order, 'key');
    119 
    120         if ($charge_result->getState() == 'captured') {
    121             $this->assertTrue($response);
    122         } else {
    123             $this->assertFalse($response);
    124         }
    125     }
    126 
    127     /**
    128      * @param null $status
    129      * @return mixed
    130      */
    131     private function get_mock_order($status = null)
    132     {
    133         $order = $this->getMock('WC_Order');
    134         $order->expects($this->any())
    135             ->method('payment_complete')
    136             ->will($this->returnValue(null));
    137 
    138         $order = $this->set_order_id($order);
    139 
    140         if(empty($status)){
    141             return $order;
    142         }
    143 
    144         $order->expects($this->any())
    145             ->method('get_status')
    146             ->will($this->returnValue($status));
    147 
    148         return $order;
    149     }
    150 
    151     /**
    152      * @dataProvider exception_provider
    153      */
    154     public function test_capture_charge_with_exception($exception)
    155     {
    156         $api_instance = $this->getMock('\zipMoney\Api\ChargesApi');
    157         $api_instance->expects($this->any())
    158             ->method('chargesCapture')
    159             ->will($this->throwException($exception));
    160 
    161         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    162             $this->payment_gateway,
    163             $api_instance
    164         );
    165 
    166         $order = self::get_mock_order();
    167 
    168         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge($order, 'key');
    169         $this->assertFalse($response);
    170     }
    171 
    172     /**
    173      * @dataProvider charge_result_provider
    174      */
    175     public function test_cancel_order_charge($charge_result)
    176     {
    177         $api_instance = $this->getMock('\zipMoney\Api\ChargesApi');
    178         $api_instance->expects($this->any())
    179             ->method('chargesCancel')
    180             ->will($this->returnValue($charge_result));
    181 
    182         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    183             $this->payment_gateway,
    184             $api_instance
    185         );
    186 
    187         $order = self::get_mock_order();
    188 
    189         //order without charge_id
    190         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->cancel_order_charge($order, 'key');
    191         $this->assertFalse($response);
    192 
    193         //order status is not authorized
    194         update_post_meta($this->get_order_id($order), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id');
    195         self::get_mock_order('processing');
    196         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->cancel_order_charge($order, 'key');
    197         $this->assertFalse($response);
    198 
    199         $order = self::get_mock_order(WC_Zipmoney_Payment_Gateway_Config::ZIP_ORDER_STATUS_AUTHORIZED_KEY_COMPARE);
    200         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->cancel_order_charge($order, 'key');
    201 
    202         if ($charge_result->getState() == 'cancelled') {
    203             $this->assertTrue($response);
    204         } else {
    205             $this->assertFalse($response);
    206         }
    207     }
    208 
    209     /**
    210      * @dataProvider exception_provider
    211      */
    212     public function test_cancel_charge_with_exception($exception)
    213     {
    214         $api_instance = $this->getMock('\zipMoney\Api\ChargesApi');
    215         $api_instance->expects($this->any())
    216             ->method('chargesCancel')
    217             ->will($this->throwException($exception));
    218 
    219         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    220             $this->payment_gateway,
    221             $api_instance
    222         );
    223 
    224         $order = self::get_mock_order();
    225 
    226         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge($order, 'key');
    227         $this->assertFalse($response);
    228     }
    229 
    230     public function test_refund_order()
    231     {
    232         $api_instance = $this->getMock('\zipMoney\Api\RefundsApi');
    233         $api_instance->expects($this->any())
    234             ->method('refundsCreate')
    235             ->will($this->returnValue(new \zipMoney\Model\Refund()));
    236 
    237         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    238             $this->payment_gateway,
    239             $api_instance
    240         );
    241 
    242         $order = self::get_mock_order();
    243 
    244         //order without charge_id
    245         $order = $this->set_order_id($order);
    246         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
    247             $order,
    248             'key',
    249             100,
    250             'Reason'
    251         );
    252         $this->assertFalse($response);
    253 
    254         update_post_meta($this->get_order_id($order), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id');
    255 
    256         //order with <=0 amount
    257         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
    258             $order,
    259             'key',
    260             0,
    261             'Reason'
    262         );
    263         $this->assertFalse($response);
    264 
    265         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
    266             $order,
    267             'key',
    268             -100,
    269             'Reason'
    270         );
    271         $this->assertFalse($response);
    272 
    273         //correct order
    274         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
    275             $order,
    276             'key',
    277             100,
    278             'Reason'
    279         );
    280         $this->assertTrue($response);
    281     }
    282 
    283     /**
    284      * @dataProvider exception_provider
    285      */
    286     public function test_refund_order_with_exception($exception)
    287     {
    288         $api_instance = $this->getMock('\zipMoney\Api\RefundsApi');
    289         $api_instance->expects($this->any())
    290             ->method('refundsCreate')
    291             ->will($this->throwException($exception));
    292 
    293         $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
    294             $this->payment_gateway,
    295             $api_instance
    296         );
    297 
    298         $order = self::get_mock_order();
    299         update_post_meta($this->get_order_id($order), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id');
    300 
    301         //correct order
    302         $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
    303             $order,
    304             'key',
    305             100,
    306             'Reason'
    307         );
    308         $this->assertFalse($response);
    309     }
    310 
    311     public function get_order_id($order){
    312         return version_compare(WC_VERSION, "3.0", "<") ? $order->id : $order->get_id();
    313     }
    314     public function set_order_id($order, $value = 1){
    315         if(version_compare(WC_VERSION, "3.0", "<")){
    316             $order->id = $value;
    317         }else{
    318             $order->expects($this->any())
    319                 ->method('get_id')
    320                 ->will($this->returnValue($value));
    321         }
    322         return $order;
    323     }
     8class ChargeApiTest extends WC_ZipmoneyPaymentGatewayTestMain {
     9
     10
     11    public function charge_result_provider() {
     12        $states = array( 'captured', 'authorised', 'cancelled' );
     13
     14        $result = array();
     15
     16        foreach ( $states as $state ) {
     17            $result[] = array(
     18                new \zipMoney\Model\Charge(
     19                    array(
     20                        'id'    => 'test',
     21                        'state' => $state,
     22                    )
     23                ),
     24            );
     25        }
     26
     27        return $result;
     28    }
     29
     30    public function exception_provider() {
     31        return array(
     32            array( new \Exception() ),
     33            array( new \zipMoney\ApiException() ),
     34        );
     35    }
     36
     37    /**
     38     * @dataProvider charge_result_provider
     39     */
     40    public function test_create_charge( $charge_result ) {
     41        $api_instance = $this->getMock( '\zipMoney\Api\ChargesApi' );
     42        $api_instance->expects( $this->once() )
     43            ->method( 'chargesCreate' )
     44            ->will( $this->returnValue( $charge_result ) );
     45
     46        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     47            $this->payment_gateway,
     48            $api_instance
     49        );
     50
     51        $order = self::get_mock_order();
     52
     53        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->create_charge( $this->WC_Session, 'key', $order );
     54
     55        $this->assertArrayHasKey( 'success', $response );
     56        $this->assertArrayHasKey( 'message', $response );
     57        $this->assertArrayHasKey( 'order', $response );
     58
     59        if ( $charge_result->getState() == 'cancelled' ) {
     60            $this->assertFalse( $response['success'] );
     61        } else {
     62            $this->assertTrue( $response['success'] );
     63        }
     64    }
     65
     66
     67    /**
     68     * @dataProvider exception_provider
     69     */
     70    public function test_create_charge_with_exception( $exception ) {
     71        $api_instance = $this->getMock( '\zipMoney\Api\ChargesApi' );
     72        $api_instance->expects( $this->once() )
     73            ->method( 'chargesCreate' )
     74            ->will( $this->throwException( $exception ) );
     75
     76        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     77            $this->payment_gateway,
     78            $api_instance
     79        );
     80
     81        $order = self::get_mock_order();
     82
     83        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->create_charge( $this->WC_Session, 'key', $order );
     84        $this->assertArrayHasKey( 'success', $response );
     85        $this->assertArrayHasKey( 'message', $response );
     86
     87        $this->assertFalse( $response['success'] );
     88    }
     89
     90    /**
     91     * @dataProvider charge_result_provider
     92     */
     93    public function test_capture_charge( $charge_result ) {
     94         $api_instance = $this->getMock( '\zipMoney\Api\ChargesApi' );
     95        $api_instance->expects( $this->any() )
     96            ->method( 'chargesCapture' )
     97            ->will( $this->returnValue( $charge_result ) );
     98
     99        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     100            $this->payment_gateway,
     101            $api_instance
     102        );
     103
     104        $order    = self::get_mock_order();
     105        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge( $order, 'key' );
     106        $this->assertFalse( $response );
     107
     108        // order status is not authorized
     109        update_post_meta( $this->get_order_id( $order ), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id' );
     110        $order    = self::get_mock_order( 'processing' );
     111        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge( $order, 'key' );
     112        $this->assertFalse( $response );
     113
     114        $order    = self::get_mock_order( WC_Zipmoney_Payment_Gateway_Config::ZIP_ORDER_STATUS_AUTHORIZED_KEY_COMPARE );
     115        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge( $order, 'key' );
     116
     117        if ( $charge_result->getState() == 'captured' ) {
     118            $this->assertTrue( $response );
     119        } else {
     120            $this->assertFalse( $response );
     121        }
     122    }
     123
     124    /**
     125     * @param null $status
     126     * @return mixed
     127     */
     128    private function get_mock_order( $status = null ) {
     129         $order = $this->getMock( 'WC_Order' );
     130        $order->expects( $this->any() )
     131            ->method( 'payment_complete' )
     132            ->will( $this->returnValue( null ) );
     133
     134        $order = $this->set_order_id( $order );
     135
     136        if ( empty( $status ) ) {
     137            return $order;
     138        }
     139
     140        $order->expects( $this->any() )
     141            ->method( 'get_status' )
     142            ->will( $this->returnValue( $status ) );
     143
     144        return $order;
     145    }
     146
     147    /**
     148     * @dataProvider exception_provider
     149     */
     150    public function test_capture_charge_with_exception( $exception ) {
     151        $api_instance = $this->getMock( '\zipMoney\Api\ChargesApi' );
     152        $api_instance->expects( $this->any() )
     153            ->method( 'chargesCapture' )
     154            ->will( $this->throwException( $exception ) );
     155
     156        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     157            $this->payment_gateway,
     158            $api_instance
     159        );
     160
     161        $order = self::get_mock_order();
     162
     163        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge( $order, 'key' );
     164        $this->assertFalse( $response );
     165    }
     166
     167    /**
     168     * @dataProvider charge_result_provider
     169     */
     170    public function test_cancel_order_charge( $charge_result ) {
     171        $api_instance = $this->getMock( '\zipMoney\Api\ChargesApi' );
     172        $api_instance->expects( $this->any() )
     173            ->method( 'chargesCancel' )
     174            ->will( $this->returnValue( $charge_result ) );
     175
     176        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     177            $this->payment_gateway,
     178            $api_instance
     179        );
     180
     181        $order = self::get_mock_order();
     182
     183        // order without charge_id
     184        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->cancel_order_charge( $order, 'key' );
     185        $this->assertFalse( $response );
     186
     187        // order status is not authorized
     188        update_post_meta( $this->get_order_id( $order ), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id' );
     189        self::get_mock_order( 'processing' );
     190        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->cancel_order_charge( $order, 'key' );
     191        $this->assertFalse( $response );
     192
     193        $order    = self::get_mock_order( WC_Zipmoney_Payment_Gateway_Config::ZIP_ORDER_STATUS_AUTHORIZED_KEY_COMPARE );
     194        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->cancel_order_charge( $order, 'key' );
     195
     196        if ( $charge_result->getState() == 'cancelled' ) {
     197            $this->assertTrue( $response );
     198        } else {
     199            $this->assertFalse( $response );
     200        }
     201    }
     202
     203    /**
     204     * @dataProvider exception_provider
     205     */
     206    public function test_cancel_charge_with_exception( $exception ) {
     207        $api_instance = $this->getMock( '\zipMoney\Api\ChargesApi' );
     208        $api_instance->expects( $this->any() )
     209            ->method( 'chargesCancel' )
     210            ->will( $this->throwException( $exception ) );
     211
     212        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     213            $this->payment_gateway,
     214            $api_instance
     215        );
     216
     217        $order = self::get_mock_order();
     218
     219        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->capture_order_charge( $order, 'key' );
     220        $this->assertFalse( $response );
     221    }
     222
     223    public function test_refund_order() {
     224        $api_instance = $this->getMock( '\zipMoney\Api\RefundsApi' );
     225        $api_instance->expects( $this->any() )
     226            ->method( 'refundsCreate' )
     227            ->will( $this->returnValue( new \zipMoney\Model\Refund() ) );
     228
     229        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     230            $this->payment_gateway,
     231            $api_instance
     232        );
     233
     234        $order = self::get_mock_order();
     235
     236        // order without charge_id
     237        $order    = $this->set_order_id( $order );
     238        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
     239            $order,
     240            'key',
     241            100,
     242            'Reason'
     243        );
     244        $this->assertFalse( $response );
     245
     246        update_post_meta( $this->get_order_id( $order ), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id' );
     247
     248        // order with <=0 amount
     249        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
     250            $order,
     251            'key',
     252            0,
     253            'Reason'
     254        );
     255        $this->assertFalse( $response );
     256
     257        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
     258            $order,
     259            'key',
     260            -100,
     261            'Reason'
     262        );
     263        $this->assertFalse( $response );
     264
     265        // correct order
     266        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
     267            $order,
     268            'key',
     269            100,
     270            'Reason'
     271        );
     272        $this->assertTrue( $response );
     273    }
     274
     275    /**
     276     * @dataProvider exception_provider
     277     */
     278    public function test_refund_order_with_exception( $exception ) {
     279        $api_instance = $this->getMock( '\zipMoney\Api\RefundsApi' );
     280        $api_instance->expects( $this->any() )
     281            ->method( 'refundsCreate' )
     282            ->will( $this->throwException( $exception ) );
     283
     284        $WC_Zipmoney_Payment_Gateway_API_Request_Charge = new WC_Zipmoney_Payment_Gateway_API_Request_Charge(
     285            $this->payment_gateway,
     286            $api_instance
     287        );
     288
     289        $order = self::get_mock_order();
     290        update_post_meta( $this->get_order_id( $order ), WC_Zipmoney_Payment_Gateway_Config::META_CHARGE_ID, 'charge_id' );
     291
     292        // correct order
     293        $response = $WC_Zipmoney_Payment_Gateway_API_Request_Charge->refund_order_charge(
     294            $order,
     295            'key',
     296            100,
     297            'Reason'
     298        );
     299        $this->assertFalse( $response );
     300    }
     301
     302    public function get_order_id( $order ) {
     303        return version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id();
     304    }
     305    public function set_order_id( $order, $value = 1 ) {
     306        if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
     307            $order->id = $value;
     308        } else {
     309            $order->expects( $this->any() )
     310                ->method( 'get_id' )
     311                ->will( $this->returnValue( $value ) );
     312        }
     313        return $order;
     314    }
    324315}
  • zipmoney-payments-woocommerce/trunk/tests/test-checkout-api.php

    r2283719 r2914592  
    66 * @package Woocommerce_Zipmoneypayment_Apiv2
    77 */
    8 class CheckoutApiTest extends WC_ZipmoneyPaymentGatewayTestMain
    9 {
    10     public function exception_provider()
    11     {
    12         return array(
    13             array(new \Exception()),
    14             array(new \zipMoney\ApiException())
    15         );
    16     }
     8class CheckoutApiTest extends WC_ZipmoneyPaymentGatewayTestMain {
    179
    18     public function test_successful_checkout()
    19     {
     10    public function exception_provider() {
     11        return array(
     12            array( new \Exception() ),
     13            array( new \zipMoney\ApiException() ),
     14        );
     15    }
    2016
    21         //set the output result
    22         $checkout_result = new \zipMoney\Model\Checkout(array('id' => 'co_IwvE8adHGKg9YMURefHDD0'));
     17    public function test_successful_checkout() {
     18        // set the output result
     19        $checkout_result = new \zipMoney\Model\Checkout( array( 'id' => 'co_IwvE8adHGKg9YMURefHDD0' ) );
    2320
    24         $api_instance = $this->getMock('\zipMoney\Api\CheckoutsApi');
    25         $api_instance->expects($this->once())
    26             ->method('checkoutsCreate')
    27             ->will($this->returnValue($checkout_result));
     21        $api_instance = $this->getMock( '\zipMoney\Api\CheckoutsApi' );
     22        $api_instance->expects( $this->once() )
     23            ->method( 'checkoutsCreate' )
     24            ->will( $this->returnValue( $checkout_result ) );
    2825
    29         $WC_Zipmoney_Payment_Gateway_API_Request_Checkout = new WC_Zipmoney_Payment_Gateway_API_Request_Checkout(
    30             $this->payment_gateway,
    31             $api_instance
    32         );
     26        $WC_Zipmoney_Payment_Gateway_API_Request_Checkout = new WC_Zipmoney_Payment_Gateway_API_Request_Checkout(
     27            $this->payment_gateway,
     28            $api_instance
     29        );
    3330
    34         $this->createOrder();
    35      
     31        $this->createOrder();
    3632
    37         //$order =  $this->getMock('WC_Order');
     33        // $order =  $this->getMock('WC_Order');
    3834
    39         $result = $WC_Zipmoney_Payment_Gateway_API_Request_Checkout->create_checkout($this->WC_Session, 'url', 'key', $this->order);
     35        $result = $WC_Zipmoney_Payment_Gateway_API_Request_Checkout->create_checkout( $this->WC_Session, 'url', 'key', $this->order );
    4036
    41         $this->assertNotEmpty($result);
    42         $this->assertNotEmpty($result->getId());
    43         $this->assertEquals(get_class($result), 'zipMoney\Model\Checkout');
    44     }
     37        $this->assertNotEmpty( $result );
     38        $this->assertNotEmpty( $result->getId() );
     39        $this->assertEquals( get_class( $result ), 'zipMoney\Model\Checkout' );
     40    }
    4541
    46     /**
    47     * @dataProvider exception_provider
    48     */
    49     // public function test_exception_checkout($exception)
    50     // {
    51     //    $api_instance = $this->getMock('\zipMoney\Api\CheckoutsApi');
     42    /**
     43    * @dataProvider exception_provider
     44    */
     45    // public function test_exception_checkout($exception)
     46    // {
     47    // $api_instance = $this->getMock('\zipMoney\Api\CheckoutsApi');
    5248
    53     //    $api_instance->expects($this->once())
    54     //        ->method('checkoutsCreate')
    55     //        ->will($this->throwException($exception));
     49    // $api_instance->expects($this->once())
     50    // ->method('checkoutsCreate')
     51    // ->will($this->throwException($exception));
    5652
    57     //     $WC_Zipmoney_Payment_Gateway_API_Request_Checkout = new WC_Zipmoney_Payment_Gateway_API_Request_Checkout(
    58     //         $this->payment_gateway,
    59     //         $api_instance
    60     //     );
    61        
    62     //     $this->createOrder();
     53    // $WC_Zipmoney_Payment_Gateway_API_Request_Checkout = new WC_Zipmoney_Payment_Gateway_API_Request_Checkout(
     54    // $this->payment_gateway,
     55    // $api_instance
     56    // );
    6357
    64     //     $result = $WC_Zipmoney_Payment_Gateway_API_Request_Checkout->create_checkout($this->WC_Session, 'url', 'key',$this->order);
     58    // $this->createOrder();
    6559
    66     //     $this->assertEmpty($result);
    67     // }
     60    // $result = $WC_Zipmoney_Payment_Gateway_API_Request_Checkout->create_checkout($this->WC_Session, 'url', 'key',$this->order);
    6861
    69     private function createOrder(){       
    70         global $woocommerce;
     62    // $this->assertEmpty($result);
     63    // }
    7164
    72        if ( ! defined( 'WOOCOMMERCE_CART' ) )
    73         define( 'WOOCOMMERCE_CART', true );
    74            
    75         if(!$this->orderD){
    76             $woocommerce->cart->add_to_cart(53);
     65    private function createOrder() {
     66        global $woocommerce;
    7767
    78             WC()->cart->calculate_totals();
     68        if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
     69            define( 'WOOCOMMERCE_CART', true );
     70        }
    7971
    80             $order_id = $woocommerce->checkout()->create_order(array());
     72        if ( ! $this->orderD ) {
     73            $woocommerce->cart->add_to_cart( 53 );
    8174
    82             $this->order = new WC_Order( $order_id );
    83         }
    84     }
     75            WC()->cart->calculate_totals();
     76
     77            $order_id = $woocommerce->checkout()->create_order( array() );
     78
     79            $this->order = new WC_Order( $order_id );
     80        }
     81    }
    8582
    8683}
  • zipmoney-payments-woocommerce/trunk/zipmoney-payment-gateway.php

    r2806192 r2914592  
    77 * Give your customers the power to pay later, interest free and watch your sales grow.
    88 * Take advantage of our fast-growing customer base, proven revenue uplift, fast and simple integration.
    9  * Version:           2.3.16
     9 * Version:           2.3.17
    1010 * Author:            Zip
    1111 * Author URI:        https://www.zip.co/
     
    1414 * Github URI:        https://github.com/zipMoney/woocommerce/
    1515 * WC requires at least: 2.6.13
    16  * WC tested up to: 6.7.0
     16 * WC tested up to: 7.5.1
    1717 *
    18  * @version  2.3.16
     18 * @version  2.3.17
    1919 * @package  Zip
    2020 * @author   Zip
Note: See TracChangeset for help on using the changeset viewer.