WebhookEventType::fromName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Stadem\VivaPayments\Enums;
4
5
enum WebhookEventType: int
6
{
7
    /** A customer’s payment has been successful */
8
    case TransactionPaymentCreated = 1796;
9
10
    /** A customer’s payment failed (but the customer may retry and the customer’s payment may - eventually - be successful) */
11
    case TransactionFailed = 1798;
12
13
    /** A commission payment has been withdrawn from your account by Viva Wallet */
14
    case TransactionPriceCalculated = 1799;
15
16
    /** A customer refund has been successfully actioned */
17
    case TransactionReversalCreated = 1797;
18
19
    /** A wallet account balance change */
20
    case AccountTransactionCreated = 2054;
21
22
    /** A bank transfer to an external IBAN has been created but not executed yet (the money has not yet been transferred from your wallet) */
23
    case CommandBankTransferCreated = 768;
24
25
    /**
26
     * A bank transfer to an external IBAN has been executed.
27
     *
28
     * In case of instant bank account transfer, money has been transferred immediately from your wallet - which is linked with your IBAN - to the external IBAN.
29
     * In case of non-instant bank account transfer, money has been transferred from your wallet - which is linked with your IBAN - but not necessarily received yet to the external IBAN
30
     */
31
    case CommandBankTransferExecuted = 769;
32
33
    /** A marketplace obligation (e.g. refund request) has been successfully sent to a marketplace seller */
34
    case ObligationCreated = 5632;
35
36
    /** A marketplace obligation (e.g. refund request) has been successfully paid by a marketplace seller */
37
    case ObligationCaptured = 5633;
38
39
    /** The requested sale transactions are available to download */
40
    case SaleTransactions = 0;
41
42
43
44
    public static function fromName(string $name): int
45
    {
46
        foreach (self::cases() as $status) {
47
            if( $name === $status->name ){
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Stadem\VivaPayments\Enums\WebhookEventType. Did you maybe forget to declare it?
Loading history...
48
                return $status->value;
49
            }
50
        }
51
        throw new \ValueError("$name is not a valid backing value for enum " . self::class );
52
    }
53
    
54
    
55
    
56
        /**
57
         * Return value as string 
58
         * Enums\PaymentMethods::fromValue(15);
59
        */
60
        
61
        public static function fromValue(int $value): string
62
        {
63
            foreach (self::cases() as $status) {
64
                if( $value === $status->value ){
65
                    return $status->name;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Stadem\VivaPayments\Enums\WebhookEventType. Did you maybe forget to declare it?
Loading history...
66
                }
67
            }
68
            throw new \ValueError("$value is not a valid backing value for enum " . self::class );
69
        }
70
    
71
72
73
74
75
}