Web_developer

google 결제 영수증 확인 본문

PHP

google 결제 영수증 확인

에잎이 2021. 7. 7. 16:35
반응형
<?php
	//compser로 구글api 설치
    include './vendor/autoload.php'; //구글api 로드

	$client = new Google_Client(); //구글api 클래스 생성
    $client->setAuthConfig('OAuth의 json파일 경로');
    $client->addScope('https://www.googleapis.com/auth/androidpublisher');
    $service = new Google_Service_AndroidPublisher($client);
    
    $package_name = "프로젝트의 패키지명";
    $product_id = '상품ID';
    $jsonPath = ''OAuth의 json파일 경로';
    $androidPublisher = 'https://www.googleapis.com/auth/androidpublisher';
    
    $purchase_token = '클라이언트에서 발급받은 구매한 토큰값'; //주문관리에서도 토큰값을 확인할수있다
	$purchase = $service->purchases_subscriptions->get($package_name, $product_id, $purchase_token);
    
    $arr['kind'] = $purchase->kind;
    $arr['startTimeMillis'] = $purchase->startTimeMillis;
    $arr['autoRenewing'] = $purchase->autoRenewing;
    
    //필요한 필드명은 본인의 소스에 맞게 제작
    //구글api 참조
    //https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptions
    
    $json = json_encode($purchase);
    echo $json;
?>

해당 소스는 구독결제 관련 소스입니다.

일반 결제 (1회성 구매, 소모성구매) 는 purchases_products를 사용해야합니다.

 

 

 

2022.07.08 구글 영수증 검증 v2 사용법에 대하여 새롭게 포스팅했습니다.

response값이 좀더 명확하게 나와 분기 처리하기 좋습니다.

https://paeci-developer.tistory.com/37

Comments