• プラグイン一覧
    - WCEX Item Combo Set
    - WCEX Amazon Pay
    - WCEX Wishlist お気に入りリスト
  • リリース情報
  • お役立ちコラム
  • お問い合わせ
  • サポート
    • よくある質問
      • WCEX Amazon Pay
      • WCEX Wishlist お気に入りリスト
      • wcex-item-combo-set
    • リファレンス
      • WCEX Amazon Pay
      • WCEX Wishlist お気に入りリスト
      • wcex-item-combo-set
新規会員登録
ログイン
新規会員登録
ログイン
カート
  • プラグイン一覧
    • - WCEX Item Combo Set
    • - WCEX Amazon Pay
    • - WCEX Wishlist お気に入りリスト
  • リリース情報
  • お役立ちコラム
  • サポート
    • - よくある質問
      • - WCEX Amazon Pay
      • - WCEX Wishlist お気に入りリスト
      • - wcex-item-combo-set
    • - リファレンス
      • - WCEX Amazon Pay
      • - WCEX Wishlist お気に入りリスト
      • - wcex-item-combo-set
  • お問い合わせ
Aivec APPs > WCEX Amazon Pay > クラス > Create
レファレンス
バージョン
2.6.4
絞り込み:

目次

  • ソース
  • 関数

フック

  • アクション
  • フィルター

ファンクション

    クラス

    Create

    Amazon Pay V2 SDK Create Refund.

    ソース #ソース

    ファイル: src/API/Refund/Create.php

    class Create extends ErrorStore
    {
    
        const TRANSACTION_AMOUNT_EXCEEDED = 'TransactionAmountExceeded';
        const INVALID_CHARGE_STATUS = 'InvalidChargeStatus';
        const TRANSACTION_COUNT_EXCEEDED = 'TransactionCountExceeded';
        const PAYMENT_METHOD_NOT_ALLOWED = 'PaymentMethodNotAllowed';
        const AMAZON_REJECTED = 'AmazonRejected';
        const PROCESSING_FAILURE = 'ProcessingFailure';
    
        /**
         * AmazonPay module object
         *
         * @var AmazonPay
         */
        private $module;
    
        /**
         * Amazon Pay order object
         *
         * @var OrderMeta
         */
        private $order;
    
        /**
         * Sets `$module` member var with dependency injection.
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @param AmazonPay $module
         * @param OrderMeta $order
         * @return void
         */
        public function __construct(AmazonPay $module, OrderMeta $order) {
            $this->module = $module;
            $this->order = $order;
            parent::__construct();
            $this->populate();
        }
    
        /**
         * Creates a Refund
         *
         * @see https://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-api-v2/refund.html#create-refund
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @param string $chargeId Charge ID
         * @param int    $refundAmount
         * @param string $currencyCode
         * @param string $softDescriptor Default: ''
         * @return array
         * @throws InvalidArgumentException Thrown by `getAmazonClient`.
         */
        public function post(
            $chargeId,
            $refundAmount,
            $currencyCode,
            $softDescriptor = ''
        ) {
            $payload = [
                'chargeId' => $chargeId,
                'refundAmount' => [
                    'amount' => $refundAmount,
                    'currencyCode' => $currencyCode,
                ],
            ];
            if (!empty($softDescriptor)) {
                $payload['softDescriptor'] = $softDescriptor;
            }
            $headers = ['x-amz-pay-Idempotency-Key' => uniqid()];
            // $_ENV[SandboxSimulation::CREATE_REFUND_SIMCODE] = 'AmazonRejected';
            $headers = (new SandboxSimulation($this->module))->createRefundSetSimCodeIfSandbox($headers);
    
            try {
                $client = $this->module->getAmazonClient();
                $result = $client->createRefund($payload, $headers);
                if ($this->module->errors->hasError($result)) {
                    $error = $this->module->errors->getAmzErrorResponse($result, $this);
                    (new Logger())->logApiResponse(new Log(
                        $this->order->getChargePermissionId(),
                        Log::ACTION_ASYNC_REFUND,
                        $error->errorcode,
                        $refundAmount,
                        $error
                    ));
                    return $error;
                }
            } catch (\Exception $e) {
                return $this->module->errors->getErrorResponse(
                    GenericErrorStore::AMAZON_PAY_SDK_CLIENT_EXCEPTION,
                    [$e->getMessage()]
                );
            }
    
            $response = json_decode($result['response'], true);
            $details = $response['statusDetails'];
            $this->order->setRefundState(
                new State(
                    $details['state'],
                    $details['reasonCode'],
                    $details['reasonDescription']
                ),
                $response['refundId'],
                $refundAmount
            );
            (new Logger())->logApiResponse(new Log(
                $this->order->getChargePermissionId(),
                Log::ACTION_ASYNC_REFUND,
                Log::RESPONSE_OK,
                $refundAmount
            ));
            return $result;
        }
    
        /**
         * Populates error store
         *
         * @see https://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-api-v2/refund.html#error-codes
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @return void
         * @throws InvalidArgumentException Thrown if duplicate errorcodes exist.
         */
        public function populate() {
            $this->addError(new GenericError(
                self::TRANSACTION_AMOUNT_EXCEEDED,
                $this->getConstantNameByValue(self::TRANSACTION_AMOUNT_EXCEEDED),
                400,
                function ($message) {
                    return $message;
                },
                __('You\'ve exceeded the maximum refund amount allowed for this Refund', 'wcexaap')
            ));
    
            $this->addError(new GenericError(
                self::INVALID_CHARGE_STATUS,
                $this->getConstantNameByValue(self::INVALID_CHARGE_STATUS),
                422,
                function ($message) {
                    return $message;
                },
                __('You tried to call a Refund operation on a Charge that is not in a Completed state. Check the Charge status for more information', 'wcexaap')
            ));
    
            $this->addError(new GenericError(
                self::TRANSACTION_COUNT_EXCEEDED,
                $this->getConstantNameByValue(self::TRANSACTION_COUNT_EXCEEDED),
                422,
                function ($message) {
                    return $message;
                },
                __('You\'ve exceeded the maximum limit of 10 Refunds per Charge', 'wcexaap')
            ));
    
            $this->addError(new GenericError(
                self::AMAZON_REJECTED,
                $this->getConstantNameByValue(self::AMAZON_REJECTED),
                422,
                function ($message) {
                    return $message;
                },
                __('Amazon has rejected the refund. You should issue a refund to the buyer in an alternate manner (for example, a gift card or store credit)', 'wcexaap')
            ));
    
            $this->addError(new GenericError(
                self::PROCESSING_FAILURE,
                $this->getConstantNameByValue(self::PROCESSING_FAILURE),
                500,
                function ($message) {
                    return $message;
                },
                __('Amazon could not process the transaction because of an internal processing error or because the buyer has already received a refund from an A-to-z claim or a chargeback. You should only retry the Refund if the Charge object is in the Captured state. Otherwise, you should refund the buyer in an alternative way (for example, a store credit or a check)', 'wcexaap')
            ));
        }
    }
    

    ソースを伸ばす ソースを縮める


    関数 #関数

    Top ↑

    • __construct — Sets `$module` member var with dependency injection.
    • populate — Populates error store
    • post — Creates a Refund

    • 新規会員登録
    • ログイン
      • プラグイン一覧
      • 会社概要
      • リリース情報
      • よくある質問
      • お役立ちコラム
      • お問い合わせ
      • 個人情報保護方針
      • 特定商取引法に基づく表記
      • 情報セキュリティ基本方針
      • 利用規約

    アイベック合同会社は「Welcart」「Amazon Pay」の公式パートナーです。

    ※Amazon、Amazon.co.jp、Amazon Payおよびそれらのロゴは、Amazon.com,inc.またはその関連会社の商標です。
    ※LINE Pay、およびLINE Pay 提携サービスのロゴは、法律上保護を受ける商標です。

    © 2025 Aivec llc All Rights Reserved.