주 콘텐츠로 건너뛰기
버전: 1.x

게이트웨이 템플릿

WooCommerce 게이트웨이 템플릿은 WooCommerce POS를 위한 맞춤 결제 게이트웨이를 만드는 출발점을 제공합니다. 이 템플릿은 완전히 기능하는 결제 게이트웨이를 구축하는 데 필요한 모든 기본 코드와 구조를 포함합니다.

기능

완전한 템플릿

필요한 모든 메서드를 갖춘 즉시 사용 가능한 게이트웨이 구조

POS 통합

WooCommerce POS 호환성을 위해 미리 구성됨

자동화된 설정

스크립트 기반 템플릿 사용자 지정

확장 가능

특정 결제 제공업체에 맞게 쉽게 수정 및 확장 가능

시작하기

옵션 1: 자동 템플릿 생성

템플릿은 특정 게이트웨이에 맞게 자동으로 템플릿을 사용자 지정하는 스크립트를 포함합니다:

  1. 저장소 복제:

    git clone https://github.com/wcpos/woocommerce-gateway-template.git
    cd woocommerce-gateway-template
  2. 설치 스크립트 실행:

    ./create-gateway.sh
  3. 프롬프트에 따라 진행:

    • 게이트웨이 이름 입력 (예: "내 결제 게이트웨이")
    • 게이트웨이 슬러그 입력 (예: "my-payment")
    • 설명 제공
    • 스크립트가 사용자 지정 플러그인을 생성합니다

옵션 2: 수동 템플릿 사용

수동 사용자 지정을 선호하는 경우:

  1. 템플릿 다운로드:

  2. 템플릿 사용자 지정:

    • {{GATEWAY_NAME}}를 게이트웨이의 표시 이름으로 바꿉니다
    • {{GATEWAY_SLUG}}를 게이트웨이의 고유 식별자로 바꿉니다
    • {{GATEWAY_DESCRIPTION}}를 게이트웨이의 설명으로 바꿉니다
  3. 파일 이름 변경:

    • wcpos-{{GATEWAY_SLUG}}.php를 게이트웨이 슬러그에 맞게 변경
    • 파일 헤더 및 플러그인 정보를 업데이트합니다

템플릿 구조

주요 플러그인 파일

주요 플러그인 파일 (wcpos-{{GATEWAY_SLUG}}.php)에는 다음이 포함됩니다:

  • 플러그인 헤더: WordPress 플러그인 정보
  • 게이트웨이 클래스: 주요 결제 게이트웨이 클래스
  • 초기화: 플러그인 설정 및 훅
  • 통합: WooCommerce POS 호환성

주요 구성 요소

게이트웨이 클래스 구조:

class WCPOS_Gateway_{{GATEWAY_CLASS}} extends WC_Payment_Gateway {
// Gateway configuration
public function __construct() { }

// Admin settings form
public function init_form_fields() { }

// Process payment (main logic goes here)
public function process_payment( $order_id ) { }

// POS-specific methods
public function payment_fields() { }
}

사용자 지정 가이드

기본 구성

  1. 게이트웨이 정보:

    $this->id = 'your_gateway_id';
    $this->title = 'Your Gateway Name';
    $this->description = 'Gateway description for customers';
    $this->method_title = 'Admin title';
    $this->method_description = 'Admin description';
  2. 지원 기능:

    $this->supports = array(
    'products',
    'refunds',
    'subscriptions', // if applicable
    );

결제 처리

핵심 결제 로직은 process_payment() 메서드에 포함됩니다:

public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );

// Your payment processing logic here
// Example: API calls, validation, etc.

if ( $payment_successful ) {
$order->payment_complete();
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
} else {
wc_add_notice( 'Payment failed', 'error' );
return array(
'result' => 'failure'
);
}
}

관리자 설정

init_form_fields()에서 관리자 설정을 구성합니다:

public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable Your Gateway',
'default' => 'yes'
),
'api_key' => array(
'title' => 'API Key',
'type' => 'text',
'description' => 'Enter your API key',
'default' => '',
'desc_tip' => true,
),
// Add more settings as needed
);
}

POS 통합

POS 전용 기능을 구현합니다:

public function payment_fields() {
// Custom payment form for POS
if ( is_admin() && isset( $_GET['page'] ) && $_GET['page'] === 'wc-pos' ) {
// POS-specific payment fields
echo '<div class="pos-payment-fields">';
// Your custom POS interface
echo '</div>';
} else {
// Standard web checkout fields
parent::payment_fields();
}
}

개발 모범 사례

코드 표준

  • 워드프레스 코딩 표준: 워드프레스 PHP 코딩 표준 준수
  • 우커머스 가이드라인: WooCommerce 개발 관행 준수
  • 보안: 입력 값 정리, 데이터 검증, 논스 사용
  • 국제화: 문자열을 __()_e()를 사용하여 번역 가능하게 만듭니다.

오류 처리

// Proper error handling
try {
$result = $this->process_api_call( $data );
if ( is_wp_error( $result ) ) {
throw new Exception( $result->get_error_message() );
}
} catch ( Exception $e ) {
$order->add_order_note( 'Payment failed: ' . $e->getMessage() );
wc_add_notice( 'Payment processing error', 'error' );
return array( 'result' => 'failure' );
}

로깅

// Add logging for debugging
if ( $this->debug ) {
$this->log( 'Payment processing started for order ' . $order_id );
}

private function log( $message ) {
if ( empty( $this->logger ) ) {
$this->logger = wc_get_logger();
}
$this->logger->info( $message, array( 'source' => $this->id ) );
}

게이트웨이 테스트

개발 환경

  1. 테스트 모드: 항상 테스트/샌드박스 모드를 구현합니다
  2. 디버그 로깅: 문제 해결을 위한 포괄적인 로깅 포함
  3. 오류 시나리오: 다양한 실패 조건 테스트
  4. POS 테스트: POS 환경에서 구체적으로 테스트합니다

테스트 케이스

  • 성공적인 결제: 주문이 올바르게 완료되는지 확인
  • 실패한 결제: 적절한 오류 처리가 이루어지는지 확인
  • 환불: 지원되는 경우 환불 기능 테스트
  • 엣지 케이스: 다양한 주문 금액 및 구성으로 테스트

배포

플러그인 패키징

  1. 개발 파일 제거: 테스트 파일 및 개발 도구 정리
  2. 버전 관리: 플러그인 헤더에서 버전 번호 업데이트
  3. 문서화: 설치 지침을 포함한 README 포함
  4. 압축 패키지: 설치 가능한 zip 파일 생성

배포

  • GitHub 릴리스: 버전 관리를 위한 GitHub 릴리스 사용
  • 워드프레스 플러그인 디렉토리: WordPress.org에 제출 고려
  • 개인 배포: 필요한 경우 자체 서버에 호스팅

고급 기능

웹훅

실시간 결제 업데이트를 위한:

public function handle_webhook() {
$payload = file_get_contents( 'php://input' );
$data = json_decode( $payload, true );

// Verify webhook signature
if ( $this->verify_webhook_signature( $payload ) ) {
$this->process_webhook_data( $data );
}
}

구독 지원

반복 결제를 위한:

// Add subscription support
$this->supports[] = 'subscriptions';
$this->supports[] = 'subscription_cancellation';
$this->supports[] = 'subscription_suspension';

다중 통화

국제 결제를 위한:

public function get_supported_currencies() {
return array( 'USD', 'EUR', 'GBP', 'CAD' );
}

리소스

문서화

템플릿 저장소

  • GitHub: woocommerce-gateway-template
  • 문제: 템플릿 문제 보고 또는 기능 요청
  • 기여: 개선사항을 풀 리퀘스트를 통해 제출

도움 받기

개발 지원을 위해:

  • 템플릿 관련 문제는 GitHub 저장소를 방문하세요
  • API 질문은 WooCommerce 개발자 문서를 확인하세요
  • 일반적인 안내를 위해 WooCommerce 개발자 커뮤니티에 참여하세요

예제 게이트웨이

구현 예제를 위해 다음 기존 맞춤 게이트웨이를 연구하세요: